Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

SORTING ALGORITHM: QUICKSORT (a) Suppose we have a version of quick sort which selects pivots using the median-of-three strategy and creates partitions in the manner

SORTING ALGORITHM: QUICKSORT

image text in transcribed

(a) Suppose we have a version of quick sort which selects pivots using the median-of-three strategy and creates partitions in the manner described in lecture. Explain how you would build an input array that would cause this version of quick sort to run in O (n2) time. Your answer should explain on a high level what your array would look like and what happens when you try running quick sort on it. You do not need to give a specific example of such a array, though you may if you think it will help make your explanation more clear. (b) Recall that merge sort works by taking an array, splitting it into two pieces, recursively sorting both pieces, then combining both pieces in O (n) time. Suppose that instead we split the array into three equally sized pieces instead of two. After we finish recursing on each of the three pieces, we merge two of the three pieces together, then merge that with the third piece to get the final sorted result. What is the worst-case asymptotic runtime of this variation on merge sort? Is it better or worse then the original version of merge sort? Be sure to justify your answers. (a) Suppose we have a version of quick sort which selects pivots using the median-of-three strategy and creates partitions in the manner described in lecture. Explain how you would build an input array that would cause this version of quick sort to run in O (n2) time. Your answer should explain on a high level what your array would look like and what happens when you try running quick sort on it. You do not need to give a specific example of such a array, though you may if you think it will help make your explanation more clear. (b) Recall that merge sort works by taking an array, splitting it into two pieces, recursively sorting both pieces, then combining both pieces in O (n) time. Suppose that instead we split the array into three equally sized pieces instead of two. After we finish recursing on each of the three pieces, we merge two of the three pieces together, then merge that with the third piece to get the final sorted result. What is the worst-case asymptotic runtime of this variation on merge sort? Is it better or worse then the original version of merge sort? Be sure to justify your answers

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

Nested Relations And Complex Objects In Databases Lncs 361

Authors: Serge Abiteboul ,Patrick C. Fischer ,Hans-Jorg Schek

1st Edition

3540511717, 978-3540511717

More Books

Students also viewed these Databases questions

Question

4. Identify cultural variations in communication style.

Answered: 1 week ago