Re:Linked List Problems (2002) [pdf]
by avodonosov on Saturday November 25, 2017 @08:34AM
(#15775914)
Thank you, super.
Re:Linked List Problems (2002) [pdf]
by linkpoint1 on Saturday November 25, 2017 @09:42AM
(#15776125)
if you program in Lisp the function list-length gives nil for circular lists.
Ninety-nine problems contains similar problems with lists.
I should have said that the difference between increments must be coprime with n to guarantee that the differece becomes 0 module n, that is both pointers get equal.
If there is a cycle of length n then eventually both pointers get into the cycle. Since at each step the distance between the two pointers is increased by one module n then the distance becomes zero. Also the time to detect the loop is bounded by the time it takes both pointers to get into the loop plus the cycle length. Also this proof shows that the key ingredient is that the difference between the pointers must be coprime with n but still n steps are required to guarantee that the difference eventually becomes zero. So there is no advantage in choosing other values for the increment of the pointers except to achieve that the slowest get faster into the cycle.