Topological Sort:

https://www.youtube.com/watch?v=Q9PIxaNGnig

For a Directed Acyclic Graph (DAG) is a linear ordering of vertices such that for every directed edge (u, v), vertex u comes before v in the ordering.

Topological Sort is not unique.

Start with one node and mark it as visited.

Then go to anyone of its child node and mark that as visited and again go to its child node.

Keep going like this till all the neighbors of the current node are visted. If yes, then push the current node in stack an dthen backtrack.

Keep going like this till all the nodes are visited and added to the stack and then finally pop them all out.

Time Complexity : O(V+E)

results matching ""

    No results matching ""