I'm trying to find cycles of length 2, 3, 4, and 5 in a directed graph. So far I've had decent luck on most inputs using the simple_cycles algorithm from networkx (https://networkx.readthedocs.io/en/stable/reference/generated/networkx.algorithms.cycles.simple_cycles.html), except in the cases with very large graphs. Is there an algorithm for finding smaller cycles that has a faster runtime?
Asked
Active
Viewed 893 times
7
-
can't you traverse recursively and having a hashmap of the (node,level) as you have visited in the recursive function so once you come to the node that also exists in the hashmap then you already know it is a cycle and then you substract the current level from the one you have in your hashset then you return that to add to a linkedlist so that at the end of recursive call you have the list that has cycles that are smaller than a certain size. – fatih tekin Oct 03 '16 at 19:07