Elect The Spanning Tree Root And Assign Port Roles

Last updated: November 29, 2026

Quick Overview

Given bridges with priority and MAC address and a list of point-to-point links with port names and costs, compute the 802.1D spanning tree result: the root bridge, each non-root bridge's root port, the designated port on every link, and which ports are blocked.

Cisco
Coding & Algorithms
Software Engineer
Cisco
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Given bridges with priority and MAC address and a list of point-to-point links with port names and costs, compute the 802.1D spanning tree result: the root bridge, each non-root bridge's root port, the designated port on every link, and which ports are blocked.

Spanning tree still protects every Catalyst campus network from Layer 2 loops, and switching software engineers must know its tie-breakers cold. This question checks whether you can turn the protocol's comparison rules into a correct algorithm and explain why it produces a loop-free tree.

What the Interviewer Expects
  • Elects the root by lowest (priority, MAC) bridge ID
  • Computes root path cost with the full tie-break chain: cost, sender bridge ID, sender port, own port
  • Chooses one designated port per segment by (root path cost, bridge ID, port)
  • Blocks every port that is neither root nor designated
  • Explains why the result contains no loops
Key Topics to Cover
spanning tree protocol
graph algorithms
tie-breaking
Layer 2 loops
shortest paths
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How does Rapid PVST+ or RSTP converge faster than this model?
  • What happens when a new switch with priority 0 is plugged in, and how does root guard help?
  • How would you handle shared segments with more than two bridges?
  • How does per-VLAN spanning tree change the computation?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: bridges = {name: (priority, mac)} and links = [(a, port_a, b, port_b, cost)]. Output: the root name and, per bridge, a map from port to root, designated or blocked. Assume point-to-po...

High-Level Design
  1. Root: the minimum bridge ID tuple (priority, mac).
  2. Root port: each non-root bridge picks the neighbor offering the best tuple `(neighbor_cost + link_cost, neighbor_BID, neighbor_port, own_port...

Submit Your Answer
Markdown supported

Related Questions