Increasing fast pointer by 2 only in Floyd cycle finding algorithm -
i going through floyd's cycle finding algorithm , had doubt.
do increase fast pointer 2 only?
is there other value should best match this?
suppose both pointers wind in cycle. relative each other, fast pointer moving 1 unit closer slow pointer on each iteration. means @ point pointers must overlap. handy property.
i suppose 3 speed , 2 speed pointer, wouldn't go faster , code more complex (have write out checks 3 pointers each step instead of 2).
Comments
Post a Comment