0

I am trying to find all the cycles in an undirected graph given the adjacency list of the vertices, with the an output of all the cycles in form of the vertices they are made up of.

For example -https://i.stack.imgur.com/Ku4fd.jpg

The example depicts the graph drawn by the adjacency list with desired cycles result

1 235
2 134
3 1245
4 235
5 134

The output from the algorithm would be

Cycles:
1 2 3
1 3 5
2 3 4 
3 4 5

Note that I am not trying to find ALL possible cycles in the graph but rather all the loops. We assume for this problem that there any vertex is connected to at least 2 others

I am new to discrete maths, algorithms and graph theory, any help would be greatly appreciated.

Seb Hill
  • 1
  • 1
  • 1
    Does "loops" mean "sequences of vertices ​ v$0$ v$_1$ v$_2$ ... v${L\hspace{.02 in}-1\hspace{-0.02 in}}$ v$L$ ​ such that ​ [ v$_0$ = v$_L$ ​ and that sequence ​ ​ ​ ​ has no other repetitions and for all elements i of {0,1,2,3,...,L-2,L-1}, there is an edge from v$_i$ to v${i+1}$"$\hspace{.02 in}$? ​ ​ ​ ​ ​ ​ ​ ​​ –  Apr 17 '16 at 19:22
  • Yes, a loop is essentially a sequence of vertices that starts from vertex i and comes back to vertex i that does not enclose any other sequences starting and finishing at vi – Seb Hill Apr 17 '16 at 19:45
  • 1
    (That's different from what I was guessing.) ​ Is "enclose" in the sense of a planar embedding, or just vi not also being an internal vertex? ​ ​ ​ ​ –  Apr 17 '16 at 19:50
  • 1
    It's not clear what you are asking for. In the first sentence, you say you want to find all cycles. Later you say you don't want to find all cycles; you want to find all loops. You never define what you mean by a loop. Please edit the question to provide a precise specification/definition of what you want and what you mean by a loop; as it stands, the question is not answerable, as it's not clear what you are looking for. – D.W. Apr 18 '16 at 05:10
  • Is your question answered by the following? http://cs.stackexchange.com/q/26271/755, http://cs.stackexchange.com/q/7216/755, http://cs.stackexchange.com/q/13693/755. – D.W. Apr 18 '16 at 05:13
  • 1
    Also posted on SO. Please do not post the same question on multiple sites. Each community should have an honest shot at answering without anybody's time being wasted. – D.W. Apr 18 '16 at 05:14
  • Apologies for the double post. What I'm asking for is a way to find all the smallest cycles possible. For example, if the sequence of vertices A-B-C-D-E-A has a possible cycle of A-B-C-A, the cycle A-B-C-A will be added to the list and the former will be ignored. The diagram I linked shows the desired outcome. In that example, there are 13 possible cycles but I am trying to find all minimum cycles, displayed by the red triangles. – Seb Hill Apr 18 '16 at 12:07

0 Answers0