Question: ( 3 points ) A randomized quick sort works as follows. For ease of discussion we assume that the sequence we want to sort, K

(3 points) A randomized quick sort works as follows. For ease of discussion we assume that the sequence we want to sort, K~=(k1,dots,kn), is a permutation of 1 to n. We randomly and uniformly pick a key k from K. Then we partition K into two subsets -K1 that has keys less than k and K2 that has keys greater than k. Then we recursively sort K1 and K2, and combine the results with k to get the sorted sequence.
The number of key comparisons will always be maximized when the keys in K are already sorted.
Let |K1| and |K2| be the number of keys in K1 and K2 respectively. The expected value of max(|K1|,|K2|) is 23n.
The algorithm will compare two keys ki and kj at most once, so the number of key comparisons is O(n2).
The probability that the algorithm will compare ki and )i>j(1 is 2i-j+1.
Let P={(i,j)|1i,jn,ij}. The expected total number of key comparisons is ((i)?,jinP1|k1-kj|+1.
 (3 points) A randomized quick sort works as follows. For ease

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!