Topological Sort Visualizer

Paste directed dependencies, run Kahn or DFS topological sort, inspect queue or stack state, and catch cycles before they break an ordering.

Nodes
6
Edges
6
Zero in
2
Ordered
0

Directed edges

Step controls

Step 1 of 14: Start Kahn's algorithm with 2 zero in-degree nodes.

Dependency graph

Start Kahn's algorithm with 2 zero in-degree nodes.

Queue Active Ordered
Topological sort graphDirected graph with 6 nodes and 6 edges.Introin 0DataStructuresin 1Algorithmsin 2Graphsin 1Toposortin 2Mathin 0

Queue and in-degree

Current queue
IntroMath
NodeIn-degreeStatus
Intro0Queued
DataStructures1Pending
Algorithms2Pending
Graphs1Pending
Toposort2Pending
Math0Queued

Topological order

No nodes have been ordered yet.

What is a Topological Sort Visualizer?

A topological sort visualizer shows how a directed acyclic graph can be ordered so each dependency appears before the node that depends on it.

This tool supports Kahn’s algorithm with in-degree tracking and DFS-based topological sorting. It also reports when the graph contains a cycle.

For the full cluster of related tools, browse the Data Structure Visualizers hub.

How to use this topological sort visualizer

  • Paste directed edges such as Intro Algorithms.
  • Choose Kahn or DFS mode.
  • Run the sort to inspect queue or stack updates.
  • Read the in-degree table and output order.
  • Fix cycle warnings by removing circular dependencies.

Topological sorting is useful for course scheduling, build pipelines, dependency resolution, and task planning.

Topological sort vs graph traversal

BFS and DFS visit graph nodes, but they do not always produce a dependency-safe order. Topological sort adds a directed acyclic graph rule: every edge must point from an earlier item to a later item.

Compare this with the Graph BFS DFS Visualizer and the Union Find Visualizer to see how graph tasks differ.

Frequently Asked Questions

What input format does this topological sort visualizer use?
Use one directed edge per line, such as `A B`, meaning A must come before B.
What is Kahn's algorithm?
Kahn's algorithm repeatedly removes nodes with zero in-degree and appends them to the topological order.
Can topological sort work with cycles?
No. A graph with a directed cycle has no valid topological ordering.
Can labels be words instead of letters?
Yes. Node labels can be letters, numbers, or short words such as task names.

Related tools