+ 2
How to detect cycle in a directed graph using c programming language?
Just give an algorithm to find cycle .
3 Antworten
+ 2
Run dfs on the graph while marking differently visited vertices and current path vertices. If you found while scanning a current path vertex, you have actually found a closed circle.
Because the graph is directed, run this again and again until visiting all vertices.
+ 1
I tried by using DFS but...not able to detect cycle for some cases!
+ 1
Could you bring a case for example? This algorithm should find a circle, if such exists.
Maybe you run the dfs only once?