Compute Spanning Tree Root Ports and Blocked Ports

Last updated: November 29, 2026

Quick Overview

Given bridges with numeric bridge IDs and point-to-point links with port names and path costs, compute the root bridge, each bridge's root port, and the set of ports that end up blocked, using standard STP tie-breaking.

Arista Networks
Coding & Algorithms
Software Engineer
Arista Networks
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Given bridges with numeric bridge IDs and point-to-point links with port names and path costs, compute the root bridge, each bridge's root port, and the set of ports that end up blocked, using standard STP tie-breaking.

Spanning tree is still deployed in enterprise and campus networks that Arista sells into, and the EOS STP agent must reach the same answer as every other vendor's implementation. The interviewer wants you to map the protocol's priority vector onto a shortest-path algorithm with exact tie-breaks.

What the Interviewer Expects
  • Pick the lowest bridge ID as root
  • Run Dijkstra where the comparison key is the full priority vector (cost, sender bridge, sender port, receiving port)
  • Choose a designated port per segment by lowest (root cost, bridge ID, port)
  • Block every port that is neither a root port nor designated
  • Handle parallel links between the same two bridges
Key Topics to Cover
Dijkstra
spanning tree protocol
tie-breaking
graphs
Layer 2 loops
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 RSTP converge faster than this computation implies?
  • What happens when the root bridge fails, and how long is traffic affected in classic STP?
  • How does MSTP change this when VLANs map to different instances?
  • How would you handle a bridge partitioned from the root?
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

Inputs: list of bridge IDs (lower is better, standing in for priority plus MAC) and links (a, port_a, b, port_b, cost). Output: root ID, map of non-root bridge to root port, set of blocked `(bridge,...

High-Level Design

STP is a shortest-path tree with deterministic ties. A bridge's root port is the port that receives the best BPDU, ordered by (root path cost, sender bridge ID, sender port ID, own port ID). Running D...


Submit Your Answer
Markdown supported

Related Questions