InterviewStack.io LogoInterviewStack.io

Graph Algorithms and Traversal Questions

Covers fundamental representations, traversal techniques, and classical algorithms for graph structured data. Candidates should understand graph representations such as adjacency list and adjacency matrix and the tradeoffs in time and space for each. Core traversal skills include implementing and reasoning about breadth first search and depth first search for reachability, traversal order, and unweighted shortest path discovery, as well as tree traversal variants and their relationship to graph traversals. Algorithmic topics include cycle detection, topological sorting for directed acyclic graphs, connected components and strongly connected components, and shortest path and pathfinding algorithms for weighted graphs including Dijkstra algorithm and Bellman Ford algorithm with discussion of negative weights and appropriate use cases. Candidates should be able to analyze time and space complexity, choose appropriate auxiliary data structures such as queues, stacks, priority queues, and union find, handle directed versus undirected and weighted versus unweighted graphs, discuss implementation details and trade offs, and explain practical applications such as dependency resolution, scheduling, pathfinding, connectivity queries, and roles of graph algorithms in system design and data processing.

EasyTechnical
76 practiced
Explain the union-find (disjoint set) data structure: the operations find and union, how path compression and union by rank/size improve performance, and why the amortized cost is nearly constant. Describe two SRE use cases where union-find is useful, such as offline connectivity queries or grouping servers by failure domain.
MediumTechnical
60 practiced
Design and describe an incremental/online approach using union-find to answer a sequence of connectivity queries on a graph that only receives edge additions (no deletions). Explain how you would implement it to support a mix of union operations and connectivity queries, and analyze amortized complexity. Mention batching strategies for performance.
HardTechnical
66 practiced
Routing loops in a microservice network cause outages and amplification. Design algorithms to detect routing loops using traces and graph analysis, and propose automated remediation steps (rate-limiting, circuit-breaking, rollback). Discuss how to handle false positives caused by sampled traces and techniques to minimize noisy detections.
HardSystem Design
64 practiced
Design a multi-region routing system for cross-datacenter traffic that minimizes latency and monetary cost subject to per-link capacity constraints and SLOs. Show how to model this as a graph or flow optimization (e.g., min-cost flow or LP), discuss exact vs approximate solvers and runtime tradeoffs, and explain strategies for real-time rerouting under failures.
EasyTechnical
59 practiced
Write a Python function that detects whether an undirected graph (adjacency list Dict[int, List[int]]) contains any cycle. The function should return True if a cycle exists and False otherwise. Explain why you must track the parent node during DFS to avoid false-positive detection from immediate back-edges. Ensure O(|V|+|E|) time.

Unlock Full Question Bank

Get access to hundreds of Graph Algorithms and Traversal interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.