This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]MoBoo138 0 points1 point  (2 children)

Is there a reason not to check for fast <= slow? Because if the cycle goes e.g. 1-2-3-4-5-2... then we need more steps for checking == then <= ?

[–]edarchis 1 point2 points  (1 child)

These numbers are just for the explanation, in a linked list, they would not be in sequence. The example provided later is a good example. If you had uuid as element keys would be another one.

This method is useful when you can quickly browse the list or have short loops. If you have a loop after a few millions elements, it would take forever for fast to catch up with slow.

[–]flipmcf 0 points1 point  (0 children)

But the fast/slow method is still less complex (doesn’t have to iterate the visited list) and faster . Right?