DSA Pattern Guide
Graphs Interview Patterns (BFS/DFS/Dijkstra/Union-Find)
Graph interview problems break down into a small set of algorithms: BFS for unweighted shortest path, DFS for reachability and cycle detection, Dijkstra for weighted shortest path with non-negative weights, and Union-Find for "are these two things connected" queries without re-traversing the graph each time. Recognizing which one a problem needs is most of the battle.
The patterns that matter
- BFS — shortest path in an unweighted graph, level-by-level exploration
- DFS — reachability, cycle detection, topological sort
- Dijkstra — shortest path with non-negative weights
- Union-Find (DSU) — connectivity queries and cycle detection in near-constant time per query
Real problems from Ediky's DSA bank
Actual problem titles, including three that specifically use Union-Find:
- "Atlanta Tourism" (Graph)
- "Coloured Pair Shortest Path" (Graph)
- "Component Bitwise-AND Queries" (Union-Find)
- "Minimum Cost Walk" (Union-Find)
A note on Union-Find specifically
Union-Find problems aren't independently filterable as their own topic yet — they're tagged within Graph. Use the search box on the problems page and search "union-find" or "dsu" to find them directly.
Practice Graph problems
11 code-judged Graph problems (including Union-Find), plus 18 deeper questions in DSA-Technical.
Open Graph problems