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.

HardTechnical
0 practiced
Explain how to detect negative cycles reachable from any node across the whole graph (not just from a single source). Which algorithm(s) would you run and how would you handle disconnected components efficiently?
MediumTechnical
0 practiced
Compare common graph sampling strategies used during GNN training: uniform neighbor sampling, importance sampling, random walks (DeepWalk/Node2Vec), and layer-wise sampling (GraphSAGE). For each, describe when it is appropriate, memory/compute trade-offs, and impact on downstream model generalization.
HardTechnical
0 practiced
Explain how you would maintain and query strongly connected components incrementally if edges are added over time in a directed graph. Discuss trade-offs between recomputing SCCs periodically vs incremental approaches, and mention algorithms or data structures that help.
MediumTechnical
0 practiced
When should you use Union-Find vs DFS/BFS to compute connected components? Compare their practical performance on large sparse graphs and discuss memory and incremental update implications for each approach.
MediumTechnical
0 practiced
Implement Dijkstra's algorithm in Python using a binary heap (heapq). Function signature: dijkstra(graph, source) -> distances dict. Graph is adjacency list mapping node -> list of (neighbor, weight), weights > 0. Aim for O(E log V). Explain how you would reconstruct shortest paths.

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.