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?
Practice
Solution
Step 1: Understand the role of a switch
A switch connects devices within the same network and forwards data only to the device it is meant for.Step 2: Compare with other options
Assigning IP addresses is done by a DHCP server, connecting different networks is done by routers, and blocking all traffic is not a switch's function.Final Answer:
To send data directly to the intended device -> Option BQuick Check:
Switch forwards data to correct device [OK]
- Confusing switch with router
- Thinking switch assigns IP addresses
- Believing switch blocks all traffic
Solution
Step 1: Define the role of a bridge
A bridge connects two or more network segments and controls the flow of data between them by filtering traffic.Step 2: Eliminate incorrect options
Assigning IP addresses is DHCP's job, wireless access is provided by access points, and encryption is done by security protocols, not bridges.Final Answer:
To connect and filter traffic between two network segments -> Option AQuick Check:
Bridge connects segments and filters traffic [OK]
- Confusing bridge with DHCP server
- Thinking bridge provides wireless access
- Assuming bridge encrypts data
Solution
Step 1: Understand bridge filtering
The bridge learns which devices are on each segment and forwards data only to the segment where the destination device is located.Step 2: Analyze options
Blocking data prevents communication, broadcasting to all devices wastes bandwidth, and assigning IP addresses is not a bridge function.Final Answer:
It will forward the data only if the destination is on segment B -> Option AQuick Check:
Bridge forwards data only to correct segment [OK]
- Thinking bridge blocks all data
- Assuming bridge broadcasts to all devices
- Confusing bridge with DHCP server
Solution
Step 1: Identify switch behavior
If a switch sends data to all devices, it behaves like a hub, often due to a missing or corrupted MAC address table.Step 2: Rule out other causes
Blocking all traffic would stop communication, IP assignment is unrelated to forwarding, and wireless access points do not cause this behavior.Final Answer:
The switch is operating in hub mode or has a faulty MAC address table -> Option CQuick Check:
Switch flooding due to MAC table issue [OK]
- Confusing IP assignment with forwarding issues
- Thinking wireless access point causes flooding
- Assuming security blocks cause flooding
Solution
Step 1: Understand bridge filtering benefits
By filtering traffic, the bridge prevents unnecessary data from crossing between segments, reducing congestion and improving speed.Step 2: Eliminate incorrect options
Allowing all devices to receive all packets causes congestion, IP assignment is DHCP's role, and encryption is handled by security protocols, not bridges.Final Answer:
It reduces unnecessary traffic between departments, improving network performance -> Option DQuick Check:
Bridge filtering reduces traffic [OK]
- Thinking bridge broadcasts all data
- Confusing bridge with DHCP server
- Assuming bridge encrypts data
Ready to prove it?
Pass the test and this pattern moves unknown
