Question: ( 3 points ) A randomized quick sort works as follows. For ease of discussion we assume that the sequence we want to sort, K
points A randomized quick sort works as follows. For ease of discussion we assume that the sequence we want to sort, ~dots, is a permutation of to We randomly and uniformly pick a key from Then we partition into two subsets that has keys less than and that has keys greater than Then we recursively sort and and combine the results with to get the sorted sequence.
The number of key comparisons will always be maximized when the keys in are already sorted.
Let and be the number of keys in and respectively. The expected value of max is
The algorithm will compare two keys and at most once, so the number of key comparisons is
The probability that the algorithm will compare and is
Let The expected total number of key comparisons is jinP
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
