patterns
22 min
graphs
trees
bfs

Pattern: Trees & Graphs

BFS/DFS, topological order, and serialization instincts.

Covers: graphs · trees · bfs · dfs

Decide BFS vs DFS fast - **Shortest path in unweighted graph** → BFS - **Connected components / flood fill** → DFS or BFS - **Cycle detection / prerequisites** → topological (Kahn) or DFS colors - **Tree level order** → BFS - **Subtree properties** → DFS returning aggregates

Graph interview checklist 1. Directed or undirected? 2. Weighted? 3. How is the graph given (edges, adj list, matrix)? 4. Can there be cycles / disconnected nodes?

Practice Course Schedule (cycle in directed graph) + Serialize Tree. Draw the state machine on the whiteboard.

Crucible — Interview prep with real proof