27-6 Randomized multithreaded algorithms
Just as with ordinary serial algorithms, we sometimes want to implement randomized multithreaded algorithms. This problem explores how to adapt the various performance measures in order to handle the expected behavior of such algorithms. It also asks you to design and analyze a multithreaded algorithm for randomized quicksort.
a. Explain how to modify the work law (27.2), span law (27.3), and greedy scheduler bound (27.4) to work with expectations when TPโ, T1โ, and Tโโ are all random variables.
b. Consider a randomized multithreaded algorithm for which 1% of the time we have T1โ=104 and T10,000โ=1, but for 99% of the time we have T1โ=T10,000โ=109. Argue that the speedup of a randomized multithreaded algorithm should be defined as E[T1โ]/E[TPโ], rather than E[T1โ/TPโ].
c. Argue that the parallelism of a randomized multithreaded algorithm should be defined as the ratio E[T1โ]/E[Tโโ].
d. Multithread the RANDOMIZED-QUICKSORT algorithm on page 179 by using nested parallelism. (Do not parallelize RANDOMIZED-PARTITION.) Give the pseudocode for your P-RANDOMIZED-QUICKSORT algorithm.
e. Analyze your multithreaded algorithm for randomized quicksort. (Hint: Review the analysis of RANDOMIZED-SELECT on page 216.)
a.
E[TPโ]E[TPโ]E[TPโ]โโฅE[T1โ]/PโฅE[Tโโ]โคE[T1โ]/P+E[Tโโ].โ
b.
E[T1โ]โE[T10,000โ]โ9.9ร108,E[T1โ]/E[TPโ]=1.
E[T1โ/T10,000โ]=104โ0.01+0.99=100.99.
c. Same as the above.
d.
RANDOMIZED-QUICKSORT(A, p, r)
if p < r
q = RANDOM-PARTITION(A, p, r)
spawn RANDOMIZED-QUICKSORT(A, p, q - 1)
RANDOMIZED-QUICKSORT(A, q + 1, r)
sync
e.
E[T1โ]E[Tโโ]E[T1โ]/E[Tโโ]โ=O(nlgn)=O(lgn)=O(n).โ