Question: Selection ( A , k ) finds the k th smallest element of an array A . For example, if A = [ 3 ,

Selection (A,k) finds the k th smallest element of an array A. For example, if A=[3,11,20,6,7,38]
and k=3, then Selection (A,k) returns 7. Here is pseudocode for a divide and conquer algorithm for
Selection.
Note that in the following pseudocode I index A starting at 1, not 0.A[s,f] is the subarray of A
from index s to f inclusive of both s and f.
(a) What is the worst case runtime of this algorithm if ChoosePivot somehow always chooses the
pivot to be the median of the array, and the array is originally size n?
(b) Create and analyze a recurrence relation for the runtime of this algorithm if ChoosePivot somehow
always chooses the pivot to be the smallest element in the array, and the array is originally size
.
(c) Now consider the case that ChoosePivot chooses a pivot uniformly at random. Consider the
random variable xij, for ijAxijzizjkzizjkzizjkikji,j?
v. What is the probability ofzi and zj being compared ifwe are trying to find the kth order
statistic, and ikj?
vi. Use linearity of expectation, and properties of the expectation value of indicator random
variables to create an explicit expression involving sums that gives the average number of
comparisons done over the coruse of the algorithm.k?
iv. What is the probability ofzi and zj being compared ifwe are trying to find the kth order
statistic, and i,j?
v. What is the probability ofzi and zj being compared ifwe are trying to find the kth order
statistic, and ikj?
vi. Use linearity of expectation, and properties of the expectation value of indicator random
variables to create an explicit expression involving sums that gives the average number of
comparisons done over the coruse of the algorithm.i, which is the number of times the ith and jth smallest elements
of A are compared at some point in the algorithm.
i. What is the sample space of this problem?
ii. Explain why xijisan indicator random variable.
iii. What is the probability ofzi and zj being compared ifwe are trying to find the kth order
statistic, and k?
iv. What is the probability ofzi and zj being compared ifwe are trying to find the kth order
statistic, and i,j?
v. What is the probability ofzi and zj being compared ifwe are trying to find the kth order
statistic, and ikj?
vi. Use linearity of expectation, and properties of the expectation value of indicator random
variables to create an explicit expression involving sums that gives the average number of
comparisons done over the coruse of the algorithm.
 Selection (A,k) finds the k th smallest element of an array

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!