Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The quicksort partition technique that you have learnt in class has a major problem. I'll illustrate the problem; you will have to fix it. Suppose,

The quicksort partition technique that you have learnt in class has a major problem. I'll illustrate the problem; you will have to fix it. Suppose, you can find the median of the array in O(n) time. You use the median as pivot to partition the array. Ideally, this will split the array into two roughly equal halves and ultimately result in an O(n log n) time quick-sort algorithm.

Recall the way the partition algorithm has been designed { all numbers less than equal to the median will be on the left half. So, if you have too many occurrences of the median, then you no longer get the half split, leading ultimately to an O(n2) time algorithm. For example, say the array is [1; 30; 5; 5; 3; 5; 5; 5]; then the median is 5. The split you get is [1; 5; 5; 5; 3; 5] and [30]; clearly, this is not a half split (in fact, nowhere near).

Fix the partition algorithm so that you achieve an O(n log n) time quick-sort algorithm when the median is provided at each recursion level; WRITE pseudo-code. Do not write a different partition algorithm; you have to modify the technique discussed in class.

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

Linked Data A Geographic Perspective

Authors: Glen Hart, Catherine Dolbear

1st Edition

1000218910, 9781000218916

More Books

Students also viewed these Databases questions

Question

What is IUPAC system? Name organic compounds using IUPAC system.

Answered: 1 week ago

Question

What happens when carbonate and hydrogen react with carbonate?

Answered: 1 week ago

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago