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 for Quicksort the median among

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) [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 points] 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. (In JAVA)

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_2

Step: 3

blur-text-image_3

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

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

Students also viewed these Databases questions