Graphs problems, grouped by pattern
Graphs show up as grids, dependencies and networks. BFS finds shortest paths in unweighted graphs, DFS explores components, topological sort orders dependencies, and Dijkstra handles weighted edges.
When to reach for it
- A grid where you move between neighbours
- Tasks with prerequisites
- Shortest path, connected components or cycles
Mistakes to watch for
- Marking visited on pop instead of on push in BFS
- Missing disconnected components
- Using BFS on weighted edges
The 18 problems
1BFS / DFS Basics
- BFS - Normal + Level by Level Animated Easy
- DFS - Recursive + Iterative Animated Easy
2Matrix Graphs
- Flood Fill Animated Easy
3Connected Components
- Number of Provinces Animated Medium
- Number of Islands Animated Medium
4BFS for shortest path
- Shortest Path in Binary Matrix Animated Medium
5DFS - Complement Trick
- Surrounded Regions Animated Medium
6Multi source BFS
- Rotting Oranges Animated Medium
- 01 Matrix Animated Medium
7Cycle Detection
- Undirected Graph Cycle Animated Medium
- Directed Graph Cycle Animated Medium
- Is Graph Bipartite? Animated Medium
8Topological Sort
- Topological sort using BFS Animated Medium
- Course Schedule Animated Medium
- Course Schedule II Animated Medium
- Alien Dictionary Animated Hard
9Dijkstra
- Network Delay Time Animated Medium
- Find the City With the Smallest Number of Neighbors at a Threshold Distance Animated Medium