I do understand Input until step 4 (If my understanding is correct) but step 5 is a bit confusing because I don't know what should I put in |S1| + |S2| ≥ k -- I'm not even sure if it's an absolute value or what. I don't get the iterations too. Uhmm
Asked
Active
Viewed 206 times
1 Answers
1
So after step 4:
- S1 contains element smaller than p
- S2 contains several occurences of p and only p's
- S3 contains element greater than p
Therefore
- if
|S1| > k
then it contains the k-th element of S - else if
|S1| + |S2| > k
then S2 contains the k-th element of S which is therefore p - else the k-th element of S in in S3. So searching the k-th element of s is the same as searching the
(k-|S1|-|S2|)
element of S3. Therefore you restart (ie iterate) the same algorithm withS = S3
andk=k-|S1|-|S2|
.
Hope this help.

hivert
- 10,579
- 3
- 31
- 56
-
What should I exactly put in |S1| + |S2| ? (is that an absolute value?) – KC-Chan Jul 15 '13 at 21:45
-
``|S1|`` is the size of the S1. So ``|S1|`` is the number of elements of S smaller than p, ``|S2|`` the number of elements of S equal to p... – hivert Jul 15 '13 at 21:57
-
So that has nothing to do with those parallel lines? Another thing sir, Iterations here is vague to me. When do I iterate? – KC-Chan Jul 15 '13 at 22:06
-
See my new explanation. – hivert Jul 15 '13 at 22:13
-
I see.. Thank you sir. I think I get that now :) – KC-Chan Jul 15 '13 at 22:31