nextupprevious
Next:7.5.3 Strong ComponentsUp:7.5 Directed Acyclic GraphsPrevious:7.5.1 Test for Acyclicity

7.5.2 Topological Sort

Topological sort is a process of assigning a linear ordering to the vertices of a DAG so that if there is an arc from vertex i to vertex j, then i appears before j in the linear ordering

int n = 0;

        void topsort (vertex v);

        /* assigns numbers to vertices accessible from v in

            reverse topological order */

        vertex w;

            {

                mark[v] = visited;

                   for (w $ \in$ L[v])

                   if (mark[w] == unvisited)

                        topsort (w);

                    number[v] = n+1

            }
 

Consider what happens when the DFS leaves a vertex x for the last time. The only arcs emanating from v are tree, forward, and cross arcs. But all these arcs are directed towards vertices that have been completely visited by the search and therefore precede x in the order being constructed.


nextupprevious
Next:7.5.3 Strong ComponentsUp:7.5 Directed Acyclic GraphsPrevious:7.5.1 Test for Acyclicity
eEL,CSA_Dept,IISc,Bangalore