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 articlesHand-written tutorials, ordered as a recommended learning path.
- 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.
- 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.
- 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.
- 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.
- 05 LC 127 — Word Ladder LeetCode 127 walked through — the wildcard-pattern adjacency trick, why BFS is mandatory, and the bidirectional speedup.
- 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.
- 07 Bellman-Ford Understand Bellman-Ford's relaxation loop, how it handles negative edges, detects negative cycles, and why it costs more than Dijkstra.
- 08 Dijkstra Learn Dijkstra's shortest path algorithm with a clean Python implementation, complexity analysis, and the priority queue intuition behind it.
- 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 Topological Sort Compare Kahn's BFS-based topological sort with DFS-based postorder, with Python implementations, complexity, and cycle detection.