Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given an array, a[i], . . . , a[j], with j i 2, let k = (i + j)/2 and choose as the partition element

Given an array, a[i], . . . , a[j], with j i 2, let k = (i + j)/2 and choose as the partition element for Quicksort the median among a[i], a[j], a[k] (i.e., the value that would be in the middle if a[i], a[j], and a[k] were sorted). This is called median-of-three partitioning. (NOTE: There are several descriptions of the median-of-three method on the web. Students are not permitted to seek out these descriptions in solving this problem.)

(a) Write pseudocode for median-of-three partitioning.

(b) What is the running time of median-of-three partitioning? Justify your answer.

(c) What is the running time of Quicksort if you use median-of-three partitioning on an input set that is already sorted? Justify your answer.

(d) Implement Quicksort using a normal pivot process and the median-of-three process described above. Test your run time analysis of medium-of-three, and then compare the average and worst case run times of Quicksort with the two pivot processes. Note that you must implement all of these algorithms from scratch. Also remember that CPU time is not a valid measure for testing run time. You must use something such as the number of comparisons.

image text in transcribed

Given an array, aa with j - i2 2, let k-(ij)/2 and choose as the partition element for QUICKSORT the median among ali], aljl, ak (i.e., the value that would be in the middle if ali], ai], and a[k] were sorted). This is called median-of-three partitioning. (NOTE: There are several descriptions of the median-of-three method on the web. Students are not permitted to seek out these descriptions in solving this problem.) (a) [15 points Write pseudocode for median-of-three partitioning (b) [15 points What is the running time of median-of-three partitioning? Justify your answer (c) [20 pointsl What is the running time of QUICKSORT if you use median-of-three partitioning on an input set that is already sorted? Justify your answer (d) [50 points Implement QUICKSORT using a normal pivot process and the median-of-three process described above. Test your run time analysis of medium-of-three, and then compare the average and worst case run times of QUICKsoRT with the two pivot processes. Note that you must implement all of these algorithms from scratch. Also remember that CPU time is not a valid measure for testing run time. You must use something such as the number of comparisons

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

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

More Books

Students also viewed these Databases questions

Question

What is American Polity and Governance ?

Answered: 1 week ago

Question

What is Constitution, Political System and Public Policy? In India

Answered: 1 week ago

Question

What is Environment and Ecology? Explain with examples

Answered: 1 week ago