Processing math: 100%

Glossary

Algo: Directed acyclic graph

A cycle in a directed graph is a circular path v0v1v2vkv0. The graph below has quite a few of them, for example, BEFB.

A graph without cycles is acyclic. It turns out we can test for acyclicity in linear time, with a single depth-first search.

Property A directed graph has a cycle if and only if its depth-first search reveals a back edge.

Proof. One direction is quite easy: if (u,v) is a back edge, then there is a cycle consisting of this edge together with the path from v to u in the search tree.

Conversely, if the graph has a cycle v0v1v2vkv0, look at the first node on this cycle to be discovered (the node with the lowest pre number). Suppose it is vi. All the other vj on the cycle are reachable from it and will therefore be its descendants in the search tree. In particular, the edge vi1vi (or vkv0 if i=0) leads from a node to its ancestor and is thus by definition a back edge. ∎

Directed acyclic graphs (DAG), or dags for short, come up all the time. They are good for modeling relations like causalities, hierarchies, and temporal dependencies.

Source: Algorithms by Dasgupta, Papadimitriou, Vazirani. McGraw-Hill. 2006.

Wikipedia