πΈοΈ JavaScript Graphs β Topic Index
A graph is a collection of nodes (vertices) connected by edges. Graphs model networks, maps, social connections, and dependencies.
Topics Covered
| # | Topic | Key Concepts |
|---|---|---|
| 1 | Basics | Representations, directed vs undirected, weighted |
| 2 | Traversal | DFS, BFS, topological sort, shortest path |
| 3 | Interview Questions | 25 classic problems |
Why Graphs?
- Universal model β maps, social networks, dependencies, states
- BFS gives shortest path in unweighted graphs
- DFS detects cycles, finds connected components, topological ordering
- Foundation for Dijkstra, Union-Find, and dynamic programming on graphs
Common Patterns
- BFS from source β shortest path, level-by-level spread (flood fill, rotten oranges)
- DFS/backtracking β all paths, cycle detection, island counting
- Topological sort β course scheduling, build order (Kahn's or DFS)
- Union-Find β connected components, redundant connections
- Multi-source BFS β 01 matrix, walls and gates