step find the in-degree indeg(nof every node in the graph step enqueue all the nodes with zero in-degree step repeat steps and until the queue is empty step remove the front node of the queue by setting front front step repeat for each neighbour of node nadelete the edge from to by setting indeg(mindeg( bif indeg(mthen enqueue mthat isadd to the rear of the queue [end of inner loop[end of loopstep exit figure algorithm for topological sort we will use queue to hold the nodes with zero in-degree the order in which the nodes will be deleted from the graph will depend on the sequence in which the nodes are inserted in the queue thenwe will use variable indegwhere indeg(nwill represent the in-degree of node notes the in-degree can be calculated in two ways--either by counting the incoming edges from the graph or traversing through the adjacency list the running time of the algorithm for topological sorting can be given linearly as the number of nodes plus the number of edges (| |+| |example consider directed acyclic graph given in fig we use the algorithm given above to find topological sort of the steps are given as belowc adjacency lists ab bcde ce de ef gd figure graph step find the in-degree indeg(nof every node in the graph indeg( indeg( indeg( indeg( indeg( indeg( indeg( step enqueue all the nodes with zero in-degree front rear queue ag step remove the front element from the queue by setting front front so front rear queue ag step set indeg(bindeg( since is the neighbour of note that indeg(bis so add it on the queue the queue now becomes front rear queue agb delete the edge from to the graph now becomes as shown in the figure below