← Back to All Algorithms

📊 Topological Sort (Kahn's Algorithm)

How It Works

  1. Compute in-degree for each vertex
  2. Add all vertices with in-degree 0 to queue
  3. Remove vertex from queue, add to result
  4. Decrease in-degree of neighbors; if 0, add to queue
  5. Repeat until queue is empty

Use Case: Task scheduling, build systems, course prerequisites

Click "Start" to compute topological order