Topological Sort
Topological sort orders the vertices of a directed acyclic graph (DAG) such that for every directed edge (u, v), u comes before v. It's used in task scheduling, build systems, and dependency resolution.
Visualizer Coming Soon
The visualizer for this algorithm is under development.
Complexity
Time Complexity:
O(V + E)Space Complexity:
O(V)Pseudocode
function TopologicalSort(graph):
inDegree = {v: 0 for all v}
for each edge (u, v):
inDegree[v]++
queue = [v where inDegree[v] == 0]
result = []
while queue is not empty:
current = queue.dequeue()
result.append(current)
for each neighbor of current:
inDegree[neighbor]--
if inDegree[neighbor] == 0:
queue.enqueue(neighbor)