Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

( 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.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essential SQLAlchemy Mapping Python To Databases

Authors: Myers, Jason Myers

2nd Edition

1491916567, 9781491916568

More Books

Students also viewed these Databases questions

Question

=+a) Draw the decision tree.

Answered: 1 week ago

Question

What requirement did Health Canada initially require of Aurora?

Answered: 1 week ago