Topological Sort
Kahn's Algorithm (BFS) for ordering vertices in a Directed Acyclic Graph (DAG).
A (in:?)
B (in:?)
C (in:?)
D (in:?)
E (in:?)
F (in:?)
Queue (0 In-Degree)
Sorted Order
Status: Click Run to start
Speed
1function topologicalSort(graph):
2 inDegree = { ... }
3 queue = [nodes with inDegree 0]
4 order = []
5
6 while queue not empty:
7 u = queue.dequeue()
8 order.push(u)
9
10 for v in neighbors(u):
11 inDegree[v]--
12 if inDegree[v] == 0:
13 queue.enqueue(v)
14
15 return order.length == nodes.length ? order : error
Currently visualizing a fixed DAG. Use the Graph Builder to create custom graphs, then export logic here (future feature).