Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

LaTeX is preferred, but handwritten and scanned solutions will also be appreciat

ID: 3691768 • Letter: L

Question

LaTeX is preferred, but handwritten and scanned solutions will also be appreciated, Thank you!

Given an array A with n elements, we want to find the k-th smallest element of A. (Formally, this is the value that occurs in position k after sorting.) Suppose we choose the pivot value to be A[1] and partitioned as in class. So we get A[1... i - 1] with elements at most A[1], A[i] has the value of A[1], and A[i + 1... n] has elements at least A[1]. There are three cases: If i k, then the fcth smallest element in A is the (i - k)th smallest element in A[i + 1... n]. Use this observation to design a recursive algorithm for finding the k-th smallest element of A, based on the above idea. You can simply cite any algorithm discussed in class. What is the worst-case time complexity of this algorithm? Now, let us choose the pivot randomly at every step. Assume all elements are distinct. Analyze the time-complexity of the new algorithm. (You'll probably get a recurrence that can solved using induction.

Explanation / Answer

1.

2.The worst case time complexity of the above algorithm is O(n).