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 75 problems

5DFS - Complement Trick

6Multi source BFS

7Cycle Detection

10Eulerian Path (Hierholzer)

11Candidate Elimination

13Minimum Spanning Tree