This link has been bookmarked by 13 people . It was first bookmarked on 03 Sep 2007, by taylortree.
-
13 Jun 12
-
29 Sep 11
-
20 Sep 11
-
05 Feb 11
-
23 May 10
-
15 May 09
varkasand the only assurance you have is that the values are between 0 and n, exclusive. Is it still possible to find a duplicated value in O(n) time and O(1) space? Feel free to stop here and try to work things out yourself, if you want.
-
10 Oct 08
-
01 Jul 08
-
03 Sep 07
-
Now, suppose that the array is of length n and only contains positive integers less than n. We can be sure (by the pigeonhole principle) that there is at least one duplicate.
-
So, how do we find the beginning of the cycle? The easiest approach is to use Floyd's cycle-finding algorithm. It works roughly like this: Start at the beginning of the sequence. Keep track of two values (call them ai and aj). At each step of the algorithm, move ai one step along the sequence, but move aj two steps. Stop when ai = aj.
-
Page Comments
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.