Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider that duplicate elements may occur in a list to be sorted by QUICK SORT. (a) Modify the pseudo code of function PARTITION so that

image text in transcribed

image text in transcribed

Consider that duplicate elements may occur in a list to be sorted by QUICK SORT.

(a) Modify the pseudo code of function PARTITION so that all elements the same as the pivot will not be considered in subsequent rounds of recursive calls.

(b) Argue that the worst case running time of the modified QUICK SORT is O(kn) if there are only k distinct elements in the input list.

(c) Which of the following upper bounds is best for the average case time complexity of the modified QUICK SORT algorithm?

(i) O(n log2 n)

(ii) O(k log2 n)

(iii) O(n log2 k)

(iv) O(k log2 k)

2. then q=PARTITION(A, p,r) QUICKSORT (A, p, q -1) QUICKSORT (A, q +1,r) 4 PARTITION (A, p, r) 1 x A[r] 3 for j p tor-1 4 do if ALj] sx then i i I exchange Ali] A[j] 7 exchange A[i+1]A[r] 8 return i 1 2. then q=PARTITION(A, p,r) QUICKSORT (A, p, q -1) QUICKSORT (A, q +1,r) 4 PARTITION (A, p, r) 1 x A[r] 3 for j p tor-1 4 do if ALj] sx then i i I exchange Ali] A[j] 7 exchange A[i+1]A[r] 8 return i 1

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_2

Step: 3

blur-text-image_3

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

Contemporary Issues In Database Design And Information Systems Development

Authors: Keng Siau

1st Edition

1599042894, 978-1599042893

More Books

Students also viewed these Databases questions