Directed Graph
A directed graph G = (V, E) is a graph such that E is not necessarily symmetric.
Topological Sorting
We want to figure out an ordering < of vertices such that:
If A < B, then A can reach B by a path but B can’t reach A by a path.
If such an ordering exists, the directed graph G can be topologically sorted. [If 1<–>2, then the graph can’t be topologically sorted(in this version of def)]
- Can we tell if a graph can be topologically sorted?
- If yes, how can we find a way?
Acyclic Graph
if there if no path in the graph such that the path form a cycle
Property: A directed graph G can be topologically sorted if and only if the graph is an acyclic graph
“if”: we will design an algorithm to do it.
“only if”: by the def, then for any pair (a,b) of vertices, we cannot have both a can get to b by a path, and b can get to a by a path. [just by definition, then this direction of proof is done]
We can then define:
- sinks (maxima) as out-degree 0 vertices
- sources (minima) as in-degree 0 vertices
- Sinks and sources are not necessarily unique
- Let S = V
- Start from a source vertex v in S with only edges going out
- Remove v out of S, and remove the edges related to v out of E, and repeat 1 until S is empty. The order of removal of v is a valid topological sort of the vertices V
Claim: If ∀