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
53 practiced
You manage ETL job dependencies expressed as a directed acyclic graph (DAG). Explain topological sort and describe both Kahn's algorithm and the DFS-based approach. How would you detect cycles before scheduling, and how would you handle tie-breaking between jobs that can run in parallel (same in-degree)?
MediumTechnical
64 practiced
Implement a Python function that enumerates all simple paths between two nodes up to maximum length k in a directed unweighted graph represented as adjacency dict. Return a list of paths (each path is a list of nodes). Discuss worst-case complexity and production safeguards you'd add to avoid explosion of results.
HardTechnical
63 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.
HardTechnical
74 practiced
Design and provide pseudocode for a delta-based incremental PageRank algorithm that processes streaming edge updates (insertions and deletions). Describe how to store node state and pending deltas, detect local convergence, bound propagation to limit compute, and reconcile state periodically with batch recomputation to avoid drift.
EasyTechnical
67 practiced
Write a PostgreSQL recursive CTE that computes all nodes reachable from a given start node_id in a directed edges table: edges(src int, dst int). The query should avoid infinite loops in the presence of cycles and return each reachable node once. Explain performance considerations and limitations when running this on very large graphs partitioned by 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.