Can anyone suggest me a method for finding all the cycles and their lengths in a directed graph. Cycles might be overlapping. Lets say the graph had 2 OVERLAPPING cycles, so answer should be 3 along with their lengths. We must find smaller as well as larger cycles in the graph.
Thanks in advance.
This code is copied from e-maxx.ru , very good web-site.
This code checks the graph for being acyclic or cyclic and if it is cyclic it finds the cycle. So just modify this code so that it does what you need. Hope it helps you.
AA: Can anyone help me? I want to learn dijkstra on heap.
BB: Here is [link] standart dijkstra. So just modify this code so that it does what you need.
This problem is NP (if exist polynomial solution for this problem, then it also gives polynomial solution for Hamiltonian cycle problem).
So, full search seems the best idea:)
I think there is solution in O(K*P(N)) where K is number of different cycles, P(N) — polynomial of N. But i don't think author understand what he wants.