Loading…
Graph interview questions cover traversal, shortest paths, cycle detection and topological ordering — often disguised as grids, dependencies or word ladders.
Graph problems are frequently not presented as graphs. A grid is a graph whose neighbours are adjacent cells, a build system is a graph of dependencies, and a word-transformation puzzle is a graph whose edges are single-character edits. Recognising the underlying graph is most of the work; once it is named, the algorithm is usually a standard traversal.
Interviewers want to hear the choice between breadth-first and depth-first justified rather than defaulted to. Breadth-first search gives the shortest path in an unweighted graph; depth-first is the natural fit for cycle detection and topological ordering. Say whether the graph is directed, whether it can contain cycles, and how you will track visited nodes — forgetting the visited set on a cyclic graph is the single most common way these solutions hang.
2 system design · 8 coding · 0/4/6 easy/medium/hard
If the input describes relationships, dependencies, transformations between states, or a grid you can move around, it is a graph. Define the nodes and the edges explicitly before choosing an algorithm.
Breadth-first when you need the shortest path or level-by-level behaviour in an unweighted graph. Depth-first when you need to detect cycles, produce a topological order, or explore whole components — and when recursion depth is not a risk.