496 views
0 votes
0 votes
RANDOMIZED-QUICKSORT(A, p, r)
1     if p < r
2     q = RANDOMIZED-PARTITION(A, p, r)
3     RANDOMIZED-QUICKSORT(A, p, q – 1)
4     RANDOMIZED-QUICKSORT(A, q + 1, r)


RANDOMIZED-PARTITION(A, p, r)
1     i = RANDOM(p, r)
2     exchange A[r] with A[i]
3     return PARTITION(A, p, r)

 

When RANDOMIZED-QUICKSORT runs, how many calls are made to the random number generator RANDOM in the worst case? How about in the best case? Give your answer in terms of  $\Theta$ notation.

1 Answer

0 votes
0 votes
In the worst case, RANDOM returns the index of the largest element each
time it’s called, so $\Theta (n)$ calls are made. In the best case, RANDOM returns
the index of the element in the middle of the array and the array has distinct
elements, so $\Theta (lg n)$ calls are made.

Related questions

0 votes
0 votes
1 answer
1
akash.dinkar12 asked Jun 28, 2019
352 views
Why do we analyze the expected running time of a randomized algorithm and not its worst-case running time?
0 votes
0 votes
2 answers
2
1 votes
1 votes
1 answer
3
akash.dinkar12 asked Jun 27, 2019
422 views
Argue that for any constant $0<\alpha\leq 1/2$, the probability is approximately $1-2\alpha$ that on a random input array, PARTITION produces a split more balanced than $...