
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

CS303: Algorithms and Data Structures Fall 2007 Assignment 4 (written) Due Date: Oct 31, 2007 (during lab hours)
/* sort A[low] thru A[high] */ Procedure QUICKSORT(A, low, high)
If low >= high then return;
/* find a pivot */ P = PIVOT(A, low, high);
/* partition A using p such that A[mid] == p; all the elements A[low] through A[mid-1] are less than p; all the elements A[mid + 1] through A[high] are greater than p; */ PARTITION(A, low, high, p, mid);
/* sort the first half */ QUICKSORT(A, low, mid-1);
/* sort the second half */ QUICKSORT(A, mid +1, high);
End;
(a) Suppose PIVOT(A, low, high) always finds the smallest element in A[low] through A[high]. Describe and analyze the complexity of QUICKSORT() using O notation. (b) Suppose PIVOT(A, low, high) always finds the median element in A[low] through A[high]. Describe and analyze the complexity of QUICKSORT() using O notation.