Arulanandan P wrote:
> Hi ,
>
>   what is the best way to find out if there are any cycles in a linked list?
>
> regards
> arulanandan

Your question doesn't have any meaning because a list has no cycles.

But if you mean how to determine if a _graph_ has no cycles, then the
usual method is to use a boolean flag in each node.  Reset all the
flags to false (to do this you need to maintain a list of nodes that
really _is_ a list).  Do a depth-first search of the graph.  At every
node, verify the flag is false and then set it to true.  If you ever
find a flag already set true, you have found a cycle.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to