the idea behind the topological sorting algorithm is unusual but simple two steps are necessarystep find vertex that has no successors the successors to vertex are those vertices that are directly "downstreamfrom it-that isconnected to it by an edge that points in their direction if there is an edge pointing from to bthen is successor to in figure the only vertex with no successors is step delete this vertex from the graphand insert its label at the beginning of list steps and are repeated until all the vertices are gone at this pointthe list shows the vertices arranged in topological order you can see the process at work by using the graphd applet construct the graph of figure (or any other graphif you preferby double-clicking to make vertices and dragging to make edges then repeatedly click the topo button as each vertex is removedits label is placed at the beginning of the list below the graph deleting vertex may seem like drastic stepbut it' the heart of the algorithm the algorithm can' figure out the second vertex to remove until the first vertex is gone if you need toyou can save the graph' data (the vertex list and the adjacency matrixelsewhere and restore it when the sort is completedas we do in the graphd applet the algorithm works because if vertex has no successorsit must be the last one in the topological ordering as soon as it' removedone of the remaining vertices must have no successorsso it will be the next-to-last one in the orderingand so on the topological sorting algorithm works on unconnected graphs as well as connected graphs this models the situation in which you have two unrelated goalssuch as getting degree in mathematics and at the same time obtaining certificate in first aid cycles and trees one kind of graph the topological-sort algorithm cannot handle is graph with cycles what' cycleit' path that ends up where it started in figure the path - - - forms cycle (notice that - - - is not cycle because you can' go from to