Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check if a directed graph is acyclic?

How do I check if a directed graph is acyclic? And how is the algorithm called? I would appreciate a reference.

like image 641
nes1983 Avatar asked Feb 24 '09 22:02

nes1983


People also ask

How can you tell if a directed graph is acyclic?

Start a DFS at that node. When traversing each edge, check whether the edge points back to a node already on your stack. This indicates the existence of a cycle. If you find no such edge, there are no cycles in that connected component.

How do you check if a graph is directed?

If you are able to find edge of opposite direction for each edge in your list, you can treat your graph as undirected (or directed with 2 opposite directed edges per pair of connected nodes). Otherwise, it is directed. (considering example above, if for vertex b there is no vertex a in its adjacent vertices list).

Is directed acyclic?

A directed acyclic graph is a directed graph that has no cycles. A vertex v of a directed graph is said to be reachable from another vertex u when there exists a path that starts at u and ends at v. As a special case, every vertex is considered to be reachable from itself (by a path with zero edges).

Is the graph cyclic or acyclic?

A cyclic graph is a graph containing at least one graph cycle. A graph that is not cyclic is said to be acyclic. A cyclic graph possessing exactly one (undirected, simple) cycle is called a unicyclic graph. Cyclic graphs are not trees.


1 Answers

I would try to sort the graph topologically, and if you can't, then it has cycles.

like image 156
FryGuy Avatar answered Sep 28 '22 21:09

FryGuy