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
53 practiced
Design a data model and Cypher-like query for friend-of-friend (FoF) suggestions in a social network using a graph database (e.g., Neo4j). Describe node and relationship types, indexes you would create, and an efficient query to return top-k suggestions for user U prioritized by number of mutual friends and recency of interaction. Discuss limitations at very large scale and caching strategies.
MediumTechnical
74 practiced
Implement the A* search algorithm in Python for pathfinding on a 4-direction grid. Input: 2D grid where 0=free, 1=obstacle, start (sx,sy) and goal (gx,gy). Use Manhattan distance as the heuristic. Return a list of coordinates representing the found path or an empty list if unreachable. Ensure proper g and f score maintenance and path reconstruction.
EasyTechnical
69 practiced
Compare use-cases for BFS and DFS. For each algorithm, list typical problems where it is the preferred approach (e.g., unweighted shortest path, cycle detection), memory usage characteristics, and scenarios where one performs better than the other (e.g., very deep vs very wide graphs). Provide practical rules-of-thumb for choosing between BFS, DFS, and bidirectional search.
HardTechnical
55 practiced
Describe Yen's algorithm for computing the K shortest simple paths between a source s and target t in a weighted directed graph (no negative cycles). Outline how to use Dijkstra as a subroutine, how to generate spur paths by temporarily removing edges and nodes, how to manage the candidate heap, and analyze the time complexity and practical tradeoffs.
MediumTechnical
58 practiced
Explain Kosaraju's algorithm to compute strongly connected components (SCCs) in a directed graph. Provide an outline for implementation: first pass to compute finishing times, transpose graph, second pass to collect SCCs. Discuss time/space complexity, memory layout considerations (storing reverse adjacency), and how to handle very large graphs in memory-constrained environments.

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.

40+ Graph Algorithms and Traversal Interview Questions & Answers (2026) | InterviewStack.io