BFS + Queue
We will have a Adjacency List, on array which consists of degree of each vertex and a Queue
Let’s see for traverse this algorithm for the graph given below.
Step 1: Find incoming degree for each vertex and store it in the array
Step 2: Push all the nodes with incoming degree zero in the Queue. As the nodes with incoming degree zero becomes the starting point of the topological Sort (in the previous blog)
Step 3: Process the queue and we will take a count variable which will keep track of how many vertices have been processed