Skip to content
C Codeloom

Topics / Graphs

🕸️

Graphs

The most versatile data structure — BFS, DFS, shortest paths, topological sort, and connected components.

Why learn Graphs?

  • Models almost every real-world relationship: networks, dependencies, maps.

  • Topo sort solves a huge family of build/scheduling problems.

  • Dijkstra and friends are everyday algorithms inside production systems.

What you can build with Graphs

BFS / DFS / shortest path Topological sort and dependency resolution Connectivity and cycle detection

Graphs tutorials

10 articles

Hand-written tutorials, ordered as a recommended learning path.

  1. 01 Graphs — Intro A practical introduction to graphs — directed vs undirected, weighted vs unweighted, cyclic vs acyclic, and the three main representations (adjacency list, adjacency matrix, edge list) with Python code.
  2. 02 BFS & DFS A practical guide to BFS and DFS on graphs — recursive and iterative DFS, BFS with a deque, shortest paths on unweighted graphs, connected components, cycle detection, and five classic practice problems.
  3. 03 LC 133 — Clone Graph LeetCode 133 walked through — why a hash map from original to copy is the entire idea, plus the BFS variant for stack-limited environments.
  4. 04 LC 417 — Pacific Atlantic LeetCode 417 explained — why you should flood from the oceans inward, not from each cell outward, and how the intersection gives the answer.
  5. 05 LC 127 — Word Ladder LeetCode 127 walked through — the wildcard-pattern adjacency trick, why BFS is mandatory, and the bidirectional speedup.
  6. 06 Course Schedule Detect cycles and produce a valid course order in LeetCode 207 Course Schedule using DFS-based topological sort. Includes BFS Kahn alternative and interview script.
  7. 07 Bellman-Ford Understand Bellman-Ford's relaxation loop, how it handles negative edges, detects negative cycles, and why it costs more than Dijkstra.
  8. 08 Dijkstra Learn Dijkstra's shortest path algorithm with a clean Python implementation, complexity analysis, and the priority queue intuition behind it.
  9. 09 MST: Kruskal & Prim Build minimum spanning trees with Kruskal's union-find approach and Prim's priority queue approach, with side-by-side Python implementations.
  10. 10 Topological Sort Compare Kahn's BFS-based topological sort with DFS-based postorder, with Python implementations, complexity, and cycle detection.