Given a directed acyclic graph, do a topological sort on this graph

Given a directed acyclic graph, do a topological sort on this graph.

Do DFS by keeping visited. Put the vertex which are completely explored into a stack.
Pop from stack to get sorted order.

Space and time complexity is O(n).

Output:
5
6
1
2
3
8
11
4

Leave a Reply

Your email address will not be published. Required fields are marked *