Graphs (3)
The notions of "shortest path" in unweighted graph and weighted graph
In an acyclic digraph (also known as DAG), after Depth-First Search the finish order list contains the reverse of the topological sorting result. The complexity is O(|V| + |E|).
A digraph can be topologically sorted as far as there is no cycle in the graph. For a digraph that may contain cycle, a common algorithm to do topological sorting and cycle detecting is to repeatedly mark or remove vertices with no (unvisited) successor (or predecessor) from the graph. The complexity is O(|V|2) when an adjacent matrix is used to implement the graph.