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.

MediumTechnical
0 practiced
Implement Kahn's algorithm for topological sorting in Python. Given a directed graph as an adjacency-list dict, return a topological order if the graph is a DAG or indicate a cycle if not. Explain complexity and how you would make the ordering deterministic across runs.
MediumTechnical
0 practiced
Implement Dijkstra's algorithm in Python to compute the shortest path and distance from a source node to a target node in a weighted graph with non-negative weights. Graph is represented as adjacency dict: {u: [(v, w), ...], ...}. Return a tuple (distance, path). Discuss time/space complexity and how your implementation handles large graphs and duplicate entries in the priority queue.
MediumTechnical
0 practiced
Explain the A* search algorithm, including the concept of admissible heuristics and heuristic consistency. Provide a data-engineering example (such as map-matching or shortest-route queries) where A* would outperform Dijkstra and discuss how you'd design or validate an admissible heuristic.
HardTechnical
0 practiced
You're optimizing a Spark GraphX job that computes shortest paths but is suffering from stragglers and heavy shuffle. Describe how you'd diagnose issues using Spark metrics and logs, and propose concrete fixes: partitioning and custom partitioners, isolating high-degree nodes, broadcast joins, caching strategy, resource tuning, and algorithmic adjustments to reduce shuffle and straggler impact.
HardTechnical
0 practiced
Compare using a dedicated graph database (e.g., Neo4j) versus implementing graph traversal queries on top of a columnar data warehouse (e.g., BigQuery) for powering a recommendation system. Consider query patterns, latency requirements, real-time updates, consistency needs, operational cost, and developer productivity. Recommend an architecture and justify your choice.

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.