Directed Acyclic Graphs (DAGs)
Directed Acyclic Graph
A graph is said to be a directed acyclic graph:
- if it is a irreflexive relation
- if it does not contain any cycles of length
Link to originalIf there is a path then there is no path .
Topological Sort
Topological Sort
A topological sort of a Directed Acyclic Graph is an ordered list of vertices , such that:
All the arrows point ‘downstream’ from to .
Link to original
Algorithm: Topological Sort
Topological Sort (Algorithm)
:
Link to original
- While vertices remain unsorted:
- Select any unsorted vertex and add to a stack
- While stack is not empty:
- Inspect top element on stack
- If has no unsorted neighbours:
- Pop from stack and add to list
- Else: add unsorted neighbours of to stack
- Return sorted list
Below is an example input and output list :

Strongly Connected Components
Strongly Connected Component
We can define a binary relation on the set of vertices such that:
A strongly connected component is therefor a maximal subset such that for all .
Link to original
Component Graph
The component graph of is a new graph where:
(vertices consist of Strongly Connected Components)
Link to original
Example Component Graph
For example, given the graph below, we have 4 strongly connected components:

If we ignore the vertices and focus on the groups, we get the following graph: (this is the component graph)

Theorem: The component graph is a DAG, for any directed graph .
- Suppose, for contradiction, that there is a cycle :

- Chose any and for some .

- It follows that there must be a path and .

- But this means that and must belong to the same component, which is a contradiction.
- Hence, by contradiction, cannot contain any cycle, as required.
Algorithm: Identify SCCs
Identify Strongly Component Components (Algorithm)
:
Link to original
- Call Topological Sort (Algorithm) to generate list .
- While is not empty:
- Inspect first element in the list.
- Perform Depth First Search (Algorithm) on the Transpose Graph from .
- Add all visited vertices to a new component .
- Remove these vertices from the list .
- Return all components identified.
