Skip to main content

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