Click to See Complete Forum and Search --> : determine if undirected graph has cycle/s


chickenandfries
February 24th, 2008, 12:49 AM
Is there an algorithm in determining whether an undirected graph has cycle/s? I've tried implementing Aho's suggestion of looking for cross edges in the breadth-first forest/tree of the graph but it doesn't seem to work. Also, if the graph has a cycle, how do I determine that cycle?

chickenandfries
February 24th, 2008, 09:40 PM
I'm done with determining if the graph has cycle/s. I checked the depth-first tree/forest for back edge/s. My problem now is to list this cycle.

chickenandfries
February 25th, 2008, 02:37 AM
Done it! Just walk through the depth-first tree/forest starting from the back edge.

Saeven
March 19th, 2008, 08:20 PM
Also easy in a digraph, just map the edges into a vertex adjacency matrix, and check for Weisstein's conjecture, which has that:

For each n = 1,2,3, … , the number of acyclic directed graphs with n labeled vertices is equal to the number of n x n matrices of 0's and 1's whose eigenvalues are positive real numbers

This can be computed very quickly, and is a great way to do things on a huge graph (walking and checking can be a killer).

sinchoss
August 15th, 2008, 06:16 PM
which data representation did you use? adjacency matrix or adjaceny list?
which one leads a faster algorithm?

ishaypeled
August 18th, 2008, 08:13 PM
Best, easiest, simplest method to find (not track down) a cycle in an undirected graph is to count the number of vertices (|V|) and the number of edges (|E|), if |E| > |V|-1 the graph contains at least one cycle (interesting to note that if |E| = |V|-1 then the graph has precisely one MST, the graph itself).