Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Quicksort with equal element values. ( 3 0 points ) The analysis of the expected running time of randomized Quicksort in class ( corresponding to

Quicksort with equal element values. (30 points) The analysis of the expected
running time of randomized Quicksort in class (corresponding to Section 7.4.2 in textbook)
assumes that all element values are distinct. In this problem, we examine what happens
when they are not, i.e., there exist same-valued elements in the array to be sorted.
The Quicksort algorithm relies on the following partition algorithm, which finds a pivot
randomly, and then put all the numbers less than or equal to the pivot in the left, and put
all the numbers greater than the pivot in the right, and then return the pivot location,
as well as the left and right sublists for recursive calls.
Algorithm 2: Partition (A,p,r)
1q=RANDOM(p,r); //generate a random number in the range of p,r
L= empty list, R= empty list;
for each element a in A except A[q] :
if aA[q] :
append a to L;
else append a to R;
A=append(L,A[q],R);
8 returen A, q;
In this algorithm, the list to be sorted is A, and we use p and r to denote the left-most and
right-most indices of the currently processing subarray, respectively. For example, in the
initial call of the Quicksort algorithm, we will let p=0 and r=n-1, which correspond to
the whole original array. The Partition (A,p,r) procedure returns an index q such that

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

Oracle Database 11g SQL

Authors: Jason Price

1st Edition

0071498508, 978-0071498500

More Books

Students also viewed these Databases questions