Skip to content

12. Graphs

🧠 Graph Strategy

  1. Model the Problem: Is it a Grid? A directed dependency (Topo)? A weighted network (Dijkstra/MST)?
  2. Choose Algorithm:
    • Shortest Path (Unweighted) -> BFS
    • Shortest Path (Weighted) -> Dijkstra
    • Connectivity/Groups -> DSU or DFS
    • Dependencies -> Topological Sort
  3. Complexity: \(O(V+E)\) for traversal, \(O(E \log V)\) for Dijkstra/Prim.

🟢 Traversal (DFS/BFS)

🟡 Grid & Multi-Source BFS

🟠 Topological Sort & Bipartite

🔴 MST & DSU (Disjoint Set)

🟣 Shortest Path (Dijkstra & Floyd)

🟤 Tree Properties & Misc