Kahn's Algorithm
Learn Kahn's Algorithm (Graphs, Advanced DSA) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
BFS-Based Topological Sort Using In-Degrees Repeatedly process any vertex with IN-DEGREE 0 (no unprocessed prerequisites) - removing it "frees up" its outgoing edges, decrementing its neighbors' in-degrees. When a neighbor's in-degree hits 0, it becomes eligible too. A queue naturally manages this "process whatever's ready" order.
More lessons in Graphs
- Graph Representation - Adjacency Matrix
- Graph Representation - Adjacency List
- Directed Graph
- Undirected Graph
- Weighted Graph
- BFS
- DFS
- Connected Components
- Cycle Detection
- Bipartite Graph
- Topological Sort
- DFS Topological Sort
- Shortest Path - BFS
- Shortest Path - Dijkstra
- Shortest Path - Bellman-Ford
- Shortest Path - Floyd-Warshall
- Minimum Spanning Tree - Prim's
- Minimum Spanning Tree - Kruskal's
- Disjoint Set Union - DSU
- Union-Find
- Strongly Connected Components - Kosaraju
- Strongly Connected Components - Tarjan
- Bridges
- Articulation Points
- Euler Path / Circuit
- Hamiltonian Path / Cycle
- Graph Coloring
- Network Flow
- Maximum Flow
- Bipartite Matching