DSA Lab

Topological sort

A topological order lists the nodes of a directed graph so that every edge points forward: every task comes after the tasks it depends on. It exists exactly when the graph has no cycle.

Topological sort: how it works

In this tool: prerequisites, cycle detection. Put in your own values and watch it change. Each operation runs one step at a time and says in plain words what happened, with its calculation worked out. The code is shown in Python, C, C++ or Java with the line that just ran marked, and an Understand it panel gives the idea, why it works, the cost of each operation, common mistakes and a short quiz.

Lessons that use it

  • Topological sort (Algorithms)Order the tasks of a directed acyclic graph so every task comes after the ones it depends on, with Kahn's algorithm.