Protocol Data Units at each layer in Computer Networks - Time & Space Complexity
When data travels through a network, it passes through several layers. Each layer adds or removes information in units called Protocol Data Units (PDUs).
We want to understand how the processing time grows as data moves through these layers.
Analyze the time complexity of processing PDUs through network layers.
// Simplified PDU processing through layers
function processData(data) {
let pdu = data;
pdu = applicationLayer(pdu); // Adds headers
pdu = transportLayer(pdu); // Adds headers
pdu = networkLayer(pdu); // Adds headers
pdu = dataLinkLayer(pdu); // Adds headers
return pdu;
}
This code shows data being wrapped with headers at each network layer to form PDUs.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Sequential processing through each network layer.
- How many times: Exactly once per layer, with a fixed number of layers.
The processing steps do not increase with the size of the data but depend on the fixed number of layers.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 bytes | 4 steps (one per layer) |
| 100 bytes | 4 steps (one per layer) |
| 1000 bytes | 4 steps (one per layer) |
Pattern observation: The number of steps stays the same regardless of data size.
Time Complexity: O(1)
This means processing time stays constant because the number of layers is fixed and does not grow with data size.
[X] Wrong: "Processing time grows with the size of the data because each layer adds headers."
[OK] Correct: Each layer processes the data once regardless of size; the number of layers is fixed, so time does not increase with data size.
Understanding fixed steps in layered processing helps you explain how network protocols handle data efficiently. This skill shows you can reason about system design and performance.
"What if the number of network layers increased dynamically with data size? How would the time complexity change?"