Re: [algogeeks] Doubt in removing loop from linked list

2012-03-10 Thread rahul sharma
1-2-3-4-5-6-7-8-9-10-11 fast and slow meet at 11 m=6; k=4 ...i cant get last two lineswhen k= sometimes around the circle - m.. then after that taking fast at begining and slow within circle ..i cant get this...@ dave plz explain with this example...will b of gr8 help..thnx in

Re: [algogeeks] Doubt in removing loop from linked list

2012-03-10 Thread Moheed Moheed Ahmad
@Rahul: As Dev said: Now start the fast pointer at the head and take m single steps with both pointers. The fast pointer is at the beginning of the cycle, and the slow pointer has traversed the cycle (2*t - u) times and is back at the beginning of the cycle. k= (2*t-u)p -m When fast pointer is

Re: [algogeeks] Doubt in removing loop from linked list

2012-03-10 Thread rahul sharma
@moheed i got it. @Dave...Thnx a lot..i got it all now... On Sat, Mar 10, 2012 at 5:56 PM, Moheed Moheed Ahmad mohe...@gmail.comwrote: @Rahul: As Dev said: Now start the fast pointer at the head and take m single steps with both pointers. The fast pointer is at the beginning of the cycle,

[algogeeks] Doubt in removing loop from linked list

2012-03-09 Thread rahul sharma
i have 2 pointers fast and slow.now if tehy meet there is a loop... now keep one ptr at meeting point and take other one to the begining of listmove both at speed of one..they will meet at start of loophow this happens???why they meet at start..plz tell logic behind this???thnx in

Re: [algogeeks] Doubt in removing loop from linked list

2012-03-09 Thread sanjiv yadav
No They will not meet at the start in a case containing 5 nods and having loop at the third node. once check this On Fri, Mar 9, 2012 at 3:48 PM, rahul sharma rahul23111...@gmail.comwrote: i have 2 pointers fast and slow.now if tehy meet there is a loop... now keep one ptr at meeting

Re: [algogeeks] Doubt in removing loop from linked list

2012-03-09 Thread Terence
@ rahul sharma: the linked list is a combination of a list a-b-...-p-q and a cycle q-r-...-z-q. (z != p). noting that the start of cycle q is the only node with 2 predecessor: p and z. if 2 pointers meet at some node x, different from q, in last step they must have met at x', the predecessor

Re: [algogeeks] Doubt in removing loop from linked list

2012-03-09 Thread rahul sharma
@terencei cant get..can u eleboratethnx for the sol..but plz elaborate... On Fri, Mar 9, 2012 at 5:59 PM, Terence technic@gmail.com wrote: @ rahul sharma: the linked list is a combination of a list a-b-...-p-q and a cycle q-r-...-z-q. (z != p). noting that the start of cycle q

Re: [algogeeks] Doubt in removing loop from linked list

2012-03-09 Thread sanjiv yadav
suppose linked list is a-b-c-d-e and suppose loop starts from 'c' according to u let one pointer be at 'c' say *q and another be at 'a' say *p. Now if we move both at the speed of one then After first pass p will be at b q will be at d After second pass p will be at c q will be at e

Re: [algogeeks] Doubt in removing loop from linked list

2012-03-09 Thread rahul sharma
@sanjiv...how can u take q at c.they will meet at some position ... suppose u have 1-2-3-4-5-6-7-4 now initialy slow and fast both at 1 start incrementing slow by 1 and fast by 2 slow @2 ...fast @3 slow @3fast @5 s...@4...fast@7 slow @5...fast@5 both are equalmeans dere is

Re: [algogeeks] Doubt in removing loop from linked list

2012-03-09 Thread sanjiv yadav
I think u r making mistake i.e. after 7,5 will com not 4 because loop starts from 5.check it again On 3/9/12, rahul sharma rahul23111...@gmail.com wrote: @sanjiv...how can u take q at c.they will meet at some position ... suppose u have 1-2-3-4-5-6-7-4 now initialy slow and fast

Re: [algogeeks] Doubt in removing loop from linked list

2012-03-09 Thread rahul sharma
itz ryt...loop starts from 4 n not from 5... On Fri, Mar 9, 2012 at 8:58 PM, sanjiv yadav sanjiv2009...@gmail.comwrote: I think u r making mistake i.e. after 7,5 will com not 4 because loop starts from 5.check it again On 3/9/12, rahul sharma rahul23111...@gmail.com wrote: