Kahn's Algorithm Visualizer

Interactive Topological Sorting Demonstration

0

Steps

Complexity Analysis

Time Complexity: O(V + E)
Space Complexity: O(V)

Algorithm Steps

1. Calculate in-degree for all vertices
2. Add vertices with in-degree 0 to queue
3. While queue is not empty:
   4. Dequeue vertex and add to result
   5. For each neighbor of vertex:
      6. Decrease neighbor's in-degree
      7. If in-degree becomes 0, enqueue
8. Check if all vertices processed

Controls

Slow Fast

Graph Visualization

Current State

Queue (vertices with in-degree 0):

Empty

Topological Order:

Empty

In-Degrees:

Step Explanation

Click "Play" or "Step" to begin the algorithm visualization.