0
0
Computer Networksknowledge~5 mins

Switching and bridging in Computer Networks - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Switching and bridging
O(n)
Understanding Time 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.

Scenario Under Consideration

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.

Identify Repeating Operations

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.
How Execution Grows With Input

The time to forward a frame grows with the number of ports when flooding is needed.

Number of Ports (n)Approx. Operations
1010 sends if flooding
100100 sends if flooding
10001000 sends if flooding

Pattern observation: The work increases directly with the number of ports when flooding occurs.

Final Time Complexity

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.

Common Mistake

[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.

Interview Connect

Understanding how switching and bridging scale helps you explain network performance and design better systems.

Self-Check

What if the switch used a more efficient method to avoid flooding? How would that change the time complexity?