[Solved]1 20 Points Suppose Disposal Worst Case Linear Time Median Subroutine Called Black Box Tak Q37200576


1. (20 points) Suppose we have at our disposal a worst-case linear-time median subroutine called “black-box”, which takes an Array A containing n elements as input and returns the median element of A in linear time (O(n)) in the worst case. Give a simple, linear-time algorithm that uses “black-box” as a subroutine and returns the ith smallest element of A in linear time. Call your function Select, write down its pseudo code, recurrence relation and solve the recurrence relation to show that it indeed runs in O(n) time. Hint: You can modify the pseudo code given in slide #5 (ch9). You need to call black-box subroutine to find the median (use this one as pivot) and replace rand-partition by partition function. Note partition function will take the median returned by black-box as pivot element. You do not need to show the details of the partition function. Randomized divide-and- conquer algorithm RAND-SELECT(A, p, q, i returns i th smallest of A[ p.. ql if p q &i > 1 then error! r ← RAND-PARTITION(A, p, q) kr-p+1 if i=k then return A[r] if i〈k rank(A[r]) k then return RAND-SELECT(A, p, r-1, i) else return RAND-SELECT(A, r + 1, q, i -k) S A[r] Show transcribed image text 1. (20 points) Suppose we have at our disposal a worst-case linear-time median subroutine called “black-box”, which takes an Array A containing n elements as input and returns the median element of A in linear time (O(n)) in the worst case. Give a simple, linear-time algorithm that uses “black-box” as a subroutine and returns the ith smallest element of A in linear time. Call your function Select, write down its pseudo code, recurrence relation and solve the recurrence relation to show that it indeed runs in O(n) time. Hint: You can modify the pseudo code given in slide #5 (ch9). You need to call black-box subroutine to find the median (use this one as pivot) and replace rand-partition by partition function. Note partition function will take the median returned by black-box as pivot element. You do not need to show the details of the partition function.
Randomized divide-and- conquer algorithm RAND-SELECT(A, p, q, i returns i th smallest of A[ p.. ql if p q &i > 1 then error! r ← RAND-PARTITION(A, p, q) kr-p+1 if i=k then return A[r] if i〈k rank(A[r]) k then return RAND-SELECT(A, p, r-1, i) else return RAND-SELECT(A, r + 1, q, i -k) S A[r]
Expert Answer
Answer to 1. (20 points) Suppose we have at our disposal a worst-case linear-time median subroutine called “black-box”, which take… . . .
OR

