Switching and bridging in Computer Networks - Time & Space Complexity
When studying switching and bridging in networks, it's important to understand how the time to process data grows as the network size increases.
We want to know how the work done by switches or bridges changes when more devices or data packets are involved.
Analyze the time complexity of the following simplified bridging process.
function forwardFrame(frame, macTable, ports) {
if (macTable[frame.destination]) {
sendToPort(frame, macTable[frame.destination]);
} else {
for (let port of ports) {
sendToPort(frame, port);
}
}
}
This code checks if the destination address is known. If yes, it sends the frame to one port. Otherwise, it floods the frame to all ports.
Look at what repeats when forwarding a frame.
- Primary operation: Looping over all ports to send the frame when destination is unknown.
- How many times: Once per port, so as many times as there are ports.
The time to forward a frame grows with the number of ports when flooding is needed.
| Number of Ports (n) | Approx. Operations |
|---|---|
| 10 | 10 sends if flooding |
| 100 | 100 sends if flooding |
| 1000 | 1000 sends if flooding |
Pattern observation: The work increases directly with the number of ports when flooding occurs.
Time Complexity: O(n)
This means the time to forward a frame can grow linearly with the number of ports when the destination is unknown.
[X] Wrong: "Forwarding a frame always takes the same time regardless of network size."
[OK] Correct: When the destination is unknown, the frame is sent to all ports, so more ports mean more work and longer time.
Understanding how switching and bridging scale helps you explain network performance and design better systems.
What if the switch used a more efficient method to avoid flooding? How would that change the time complexity?