Directed Acyclic Graphs (DAGs)

Directed Acyclic Graph

A graph is said to be a directed acyclic graph:

If there is a path then there is no path .

Link to original

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)

:

  1. While vertices remain unsorted:
    1. Select any unsorted vertex and add to a stack
    2. While stack is not empty:
      1. Inspect top element on stack
      2. If has no unsorted neighbours:
        1. Pop from stack and add to list
      3. Else: add unsorted neighbours of to stack
  2. Return sorted list
Link to original

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 .

  1. Suppose, for contradiction, that there is a cycle :
  2. Chose any and for some .
  3. It follows that there must be a path and .
  4. But this means that and must belong to the same component, which is a contradiction.
  5. Hence, by contradiction, cannot contain any cycle, as required.

Algorithm: Identify SCCs

Identify Strongly Component Components (Algorithm)

:

  1. Call Topological Sort (Algorithm) to generate list .
  2. While is not empty:
    1. Inspect first element in the list.
    2. Perform Depth First Search (Algorithm) on the Transpose Graph from .
    3. Add all visited vertices to a new component .
    4. Remove these vertices from the list .
  3. Return all components identified.
Link to original