I would like to detect all the cycles(non duplicate) in a given graph, I mean if A-B-C-A is a cycle, then A-C-B-A is a duplicate of previous one and need to be considered.I could use DFS and detect a cycle, but what if i want to continue to find other cycles? how would i make any node to be considered for other cycle?
Asked
Active
Viewed 767 times
0
-
There can be exponentially many cycles in a graph, so you could just try every sequence of distinct vertices (up to cyclic permutations) and check whether it's a cycle. – Shaull Feb 02 '16 at 10:19
-
2@Shaull That would have bad time complexity in terms of output size. – Yuval Filmus Feb 02 '16 at 10:40
-
1@YuvalFilmus - for a $k$-clique this would be optimal (although there are of course examples on which it would be terrible). – Shaull Feb 02 '16 at 10:52
-
See http://cs.stackexchange.com/q/7216/755 and http://cs.stackexchange.com/q/18342/755. – D.W. Feb 04 '16 at 07:59
1 Answers
0
Following is an algorithm better than the brute force search.
Given graph $G$, find the DFS tree $T$ of $G$. We know from the structural property of $T$ that any for edge $(u,v)$ in $G$, we have that either $u$ is an ancestor of $v$ in $T$ or $v$ is an ancestor of $u$ in $T$. Therefore, brute force search for cycles in $G$ only along subsets of the branches in $T$. This is equal to the trivial brute force search if $G$ is a clique but better otherwise.
However, one can hope for better heuristics. For instance, see [1].
[1] Hongbo Liu, Jiaxin Wang: A new way to enumerate cycles in graph. AICT/ICIW 2006: 57.

Karthik C. S.
- 338
- 1
- 8