vivekkumar,
Originally posted by vivekkumar sharma:
Hi,
do bit of Google
I do made a search before I posted this question before. The issue is that, I do not know the name of the algorithm so that I can not find much useful information from Google. Could you help please? :-)
Originally posted by vivekkumar sharma:
Otherwise to detect a circle in a graph ,
keep track of nodes visited starting from a particular node,(using a set may be helpful) and if u get same node from where you started ,you have detected a circle.
I have tried this method. I do not think this method is correct. For example, suppose in a simple graph, there are four nodes, A, B, C, D. The directed graph has the following edges,
A-->B
A-->C
B-->D
C-->D
In this graph, there is no cycle. But when running your method, since node D will be accessed twice both by node B and by node C, the directed graph will be detected cycle by your method.
Maybe I do not quite understand your method, could you provide a simple implementaion of your method please?
regards,
George