4 Answer Following Question Quicksort Algorithm Implemented Pseudocode Partition Array Fir Q37081103

4. Answer the following question on Quicksort algorithmimplemented in the pseudocode below:

// Partition array A[first…last] usingA[last]

// as pivot value

Partition (A, first, last)

x = A[last]

i = first-1

for j=first to last-1

if (A[j] <= x)

i = i+1

swap (A[i], A[j])

swap(A[i+1], A[last])

return i+1

// Sort array A[first… last]

Quicksort (A, first, last)

if first < last

q = Partition (A, first, last)

Quicksort (A, first, q-1)

Quicksort (A, q+1, last)

a. Trace the first Partition() call when the aboveQuicksort is called to sort the following array. Please illustratethe array after each swap() statements.

A[1…8]

6 1 4 2 3 2 7 5

4b. Give an input to QuickSort (i.e., the array A) thatyields the worst

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.