yog/property/cyclicity

Graph cyclicity and Directed Acyclic Graph (DAG) analysis.

This module provides efficient algorithms for detecting cycles in graphs, which is fundamental for topological sorting, deadlock detection, and validating graph properties.

Algorithms

ProblemAlgorithmFunctionComplexity
Cycle detection (directed)Kahn’s algorithmis_acyclic/1, is_cyclic/1O(V + E)
Cycle detection (undirected)Union-Find / DFSis_acyclic/1, is_cyclic/1O(V + E)

Key Concepts

Cycle Detection Methods

Directed Graphs (Kahn’s Algorithm):

Undirected Graphs:

Applications of Cycle Detection

Relationship to Other Properties

References

Values

pub fn is_acyclic(graph: model.Graph(n, e)) -> Bool

Checks if the graph is a Directed Acyclic Graph (DAG) or has no cycles if undirected.

For directed graphs, a cycle exists if there is a path from a node back to itself. For undirected graphs, a cycle exists if there is a path of length >= 3 from a node back to itself, or a self-loop.

Time Complexity: O(V + E)

pub fn is_cyclic(graph: model.Graph(n, e)) -> Bool

Checks if the graph contains at least one cycle.

Logical opposite of is_acyclic.

Time Complexity: O(V + E)

Search Document