On Sat, Mar 27, 2010 at 12:11 AM, Sanjana <[email protected]> wrote:

> Hello,
> Can someone help me out with this. How to find the middle of a singly
> linked list which also has  a cycle in it.
>

Having a cycle will not cause much trouble.
We can do that using additional data structure array to keep track of the
elements and no. of times they are visited.
If any element is visited more than once We stop.It means we have entered a
cycle and now only repetition of elements will be there.
Since we are using randomly accessable D.S. Array we can simply go to the
middle of the array if it is odd and 2 middle ones if it is even.

eg.
Node No.             1 2 3 4 5 6
Times visited        1 2 1 1 1 1

2 is visited 2 times so we stop.
Since array has 6 elements.Our middle elts are 3 and 4.

>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<algogeeks%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
Thanks & Regards
Nikhil Agarwal
Junior Undergraduate
Computer Science & Engineering,
National Institute Of Technology, Durgapur,India
http://tech-nikk.blogspot.com

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to