Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

a) What is the running time of RANDOMIZED-QUICKSORT algorithm (unmodified) as given in Lecture 5 (and in the book) when applied to an array where

image text in transcribed

image text in transcribedimage text in transcribed

a) What is the running time of RANDOMIZED-QUICKSORT algorithm (unmodified) as given in Lecture 5 (and in the book) when applied to an array where all elements are equal (i.e., Ali]- A] for all i,j E n)? b) If we expect many equal elements in the input array, it is better for QUICKSORT to use a modified PARTITION routine that partitions subarrays with respect to the pivot z into 3 parts consisting of elements x,-x x respectively. Give such a modified PARTITION routine so that it partitions in place a subarray A|l,...r] with respect to a pivot element x- Alr] into three parts as suggested above. The routine should permute the elements of the subarray and return a pair of indices (g1,92) such that, in the final subarray all elements of Al,...qi] are smaller than the pivot x, all elements of Ali 1,...q2] are equal to x, and all elements of Ag2 +1,... r] are greater than r. a) What is the running time of RANDOMIZED-QUICKSORT algorithm (unmodified) as given in Lecture 5 (and in the book) when applied to an array where all elements are equal (i.e., Ali]- A] for all i,j E n)? b) If we expect many equal elements in the input array, it is better for QUICKSORT to use a modified PARTITION routine that partitions subarrays with respect to the pivot z into 3 parts consisting of elements x,-x x respectively. Give such a modified PARTITION routine so that it partitions in place a subarray A|l,...r] with respect to a pivot element x- Alr] into three parts as suggested above. The routine should permute the elements of the subarray and return a pair of indices (g1,92) such that, in the final subarray all elements of Al,...qi] are smaller than the pivot x, all elements of Ali 1,...q2] are equal to x, and all elements of Ag2 +1,... r] are greater than r

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

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

8th Edition

013460153X, 978-0134601533

More Books

Students also viewed these Databases questions

Question

Design a cross-cultural preparation program. page 313

Answered: 1 week ago

Question

Evaluate employees readiness for training. page 289

Answered: 1 week ago