Question: 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. points The analysis of the expected
running time of randomized Quicksort in class corresponding to Section in textbook
assumes that all element values are distinct. In this problem, we examine what happens
when they are not, ie there exist samevalued 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 : Partition
RANDOM generate a random number in the range of
empty list, empty list;
for each element in A except :
if :
append a to ;
else append a to ;
append;
returen q;
In this algorithm, the list to be sorted is and we use and to denote the leftmost and
rightmost indices of the currently processing subarray, respectively. For example, in the
initial call of the Quicksort algorithm, we will let and which correspond to
the whole original array. The PARTITION procedure returns an index such that
each element of : is less than or equal to and each element of :
is greater than
a points Suppose there are elements and all element values are equal. What
would be randomized Quicksort's running time in this case?
b points Modify the PARTITION procedure to produce a procedure
which permutes the elements of : and returns two indices and where
such that:
i all elements of : are equal,
ii each element of : is less than and
iii. each element of : is greater than
Like PARTITION, your PARTITON' procedure should take time.
c points Now you have a algorithm, based on this algo
rithm, provide the pseudocode of a QUICKSORT algorithm which calls PAR
as a subroutine, so that it recurses only on partitions of elements
not known to be equal to each other. Hint: it will looks very similar to our Quick
sort pseudocode in the lecture slides, you only need to make minor modifications to
recurse on the partitions produced by
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
