Saturday 12 October 2013

Topological Sort (only for directed Acyclic Graph)

Step1 : Find the indegree of all the vertices of the graph.
Step2 : Place the vertices whose indegree is „0‟ on an empty queue.
Step3 : Dequeue the vertex V and decrement the indegrees of all its adjacent vertices.
Step4 : Enqueue the vertex whose indegree has fallen to „0‟.
Step5 : Repeat from step3 untill the queue becomes empty.
Step6 : The topological sorting order is the order in which the vertices are dequeued.

No comments:

Post a Comment