First of all, I am not sure about replying using gmail but reply using g-groups with proper reply button will surely maintain the proper hierarchy.
Let us try to make a habit when replying to a specific post :
1. Using the proper reply button
2. Acknowledge the name of the person that you are referring.
3. If you are commenting about the specific line in the previous comment then better reuse that line prefixed with ">>"
and Lets not keep many open threads running parallel ..
As far as I recall there are multiple solutions for this ..
1. The more elegant one is the one specified in the link ..
a. It is based on the principle that in any complete circular list, starting two pointer at a specific point, say at node X, and at each step incrementing one pointer by one and other by two then they both meet at the node X.
If we closely observe the behavior then we know why the above one is true.
2. The solution Shyam was proposing, With the extra O(n) memory and with reversing the pointers in another copy.
a. Make a duplicate copy (and store the addresses of the original list used for comparison purpose), Say List-2.
b. Find the loop using the regular (+1, +2) method and assume both pointer meet at a node say Y.
b. Reverse the pointers in the second list.
c. Calculate the distance from head to Y using original list, Say List-1.
d. Calculate the distance from head to Y using List-2.
e. Keep two pointers (one P1 on List-1 and another one P2 on List-2) starting at position Y and move towards to root using two different directions.. Decrement the longer list pointer by difference.
f. Compare P2 value with the address of P1 by decrementing position by position.
3. Even worse than the earlier two..
a. Find the loop. Assume both pointers meet at Y. Start pointer P1 at Y.
b. FInd the distance between root and P1.
c. Increment the P1 and find the distance, if the current distance < previous distance then call this as loop node.
d. To decrease the number of distance calculations we can use one sided binary search logic to increment the pointer P1.
-- SURI