I get an interview question about the Floyd's cycle-finding algorithm :
When will Floyd's cycle-finding algorithm fail ?
I mean, is there rule for finding the step between the fast and slow pointers ?
I get an interview question about the Floyd's cycle-finding algorithm :
When will Floyd's cycle-finding algorithm fail ?
I mean, is there rule for finding the step between the fast and slow pointers ?
Under reasonable assumptions, it won't fail. It will either find a cycle or conclude that there isn't one.
The only failure scenarios I can think of are along the following lines:
f(x)in the linked algorithm returns null when passed null, then it will not fail, but that artifact appears left out (or I didn't see it, quite possible). - WhozCraig