Cycle (graph Theory) - Cycle Detection

Cycle Detection

An undirected graph has a cycle if and only if a depth-first search (DFS) finds an edge that points to an already-visited vertex (a back edge). Equivalently, all the back edges, which DFS skips over, are part of cycles. In the case of undirected graphs, only O(n) time is required, since at most n − 1 edges can be tree edges (where n is the number of vertices).

A directed graph has a cycle if and only if a DFS finds a back edge. Forward and cross edges do not necessarily indicate cycles. Many topological sorting algorithms will detect cycles too, since those are obstacles for topological order to exist. Also, if a directed graph has been divided into strongly connected components, cycles only exist within the components and not between them, since cycles are strongly connected.

Applications of cycle detection include the use of wait-for graphs to detect deadlocks in concurrent systems.

Read more about this topic:  Cycle (graph Theory)

Famous quotes containing the word cycle:

    Only mediocrities progress. An artist revolves in a cycle of masterpieces, the first of which is no less perfect than the last.
    Oscar Wilde (1854–1900)