Understanding the topological sort algorithm


The topological sort algorithm sorts the nodes of a graph in a topological order. For the algorithm to work, the graph should be a directed acyclic graph, as no topological order exists for a cyclic graph. Moreover, there can be many topological orders for a directed acyclic graph, and all of them can be correct. In this lesson, we will learn about the depth-first search-based algorithm used to find a topological order.

Loading Image

A directed acyclic graph can have multiple correct topological orderings.

Algorithm

Liking the course? Check our discounted plans to continue learning.