Idea behind the algorithm:

Push all vertices that indegree 0 on to a queue.

Repeat until queue is empty

Remove vertex v from queue.

Output v

for all vertices w adjacent to v

decrement the indegree of w.

if indegree of w becomes zero add it to queue

Code ( for the problem):

## No comments :

Post a Comment