Question
Question: Given an array, a[i], . . . , a[j], with j i 2, let k = (i + j)/2 and choose as the... (1
Question: Given an array, a[i], . . . , a[j], with j i 2, let k = (i + j)/2 and choose as the... (1 bookmark) 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. Code needed in java.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started