Given a symmetric adjacency matrix, determine the number of unique undirected cycles.
For example, the graph represented by adjacency matrix
A = [ 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 0 1 0 0];
has 6 cycles. They are:
[1 -> 2 -> 3 -> 1] [1 -> 3 -> 5 -> 1] [2 -> 3 -> 4 -> 2] [1 -> 2 -> 4 -> 3 -> 1] [1 -> 2 -> 3 -> 5 -> 1] [1 -> 2 -> 4 -> 3 -> 5 -> 1]
The input is an adjacency matrix of 0s and 1s, and the output should be the number of unique (simple) undirected cycles in the graph.
could you please clarify, in your example, why cycles like '1->2->1', '1->5->1' or '3->5->3' are not counted?
it seems the expected solution only counts cycles that include three or more nodes... is this correct?
That is correct. In a directed graph, the cycle 1 -> 2 -> 1 actually uses two different edges, while in an undirected graph, the edge 1 -> 2 and 2 -> 1 are one and the same. I am only considering cycles valid if each node along the way is visited once and if edges are not used more than one time. I chose this criteria so that the number of cycles counted would match the results for the table provided here: http://mathworld.wolfram.com/GraphCycle.html
got it. Thanks for the clarification!
Can you please send me your code for this??? Really struggling on this for a school assignment clarkieg123@gmail.com
Can you please send me your code for this??? Really struggling on this for a school assignment clarkieg123@gmail.com
Can you please send me your code for this??? Really struggling on this for a school assignment clarkieg123@gmail.com
134 Solvers
61 Solvers
64 Solvers
532 Solvers
Flag largest magnitude swings as they occur
522 Solvers