righ 2.Rand(left….right) 3. If Alk return i If A>k t return no solution . return RandomBinarySearch(A,k,left, i-1) 5. If All< . RandomBinarySearch(A,k,i+1,right) In this question, we will figure out the expected running time of this RandomBinarySearch. Note that all the work done by the algorithm consists of comparing some Alto k (and then recursing and comparing some other Al to k). In particular, each Ai is compared to k either 0 or 1 times. The expected running time is thus the expected number of comparisons made by the algorithm. For now, let assume that k does exist somewhere in the array, and figure out the expected running time for that case. Define indicator random variables Xi x,, where Xi = 1 if Ali] is compared to k, and 0 otherwise. For example, X5 -1 if 5 is chosen as the random index in line two for some recursive call, and Xs0 if 5 is never chosen. Part 1 (5 points): What is E[Xi]? Do you see why it depends on the value of k? In particular, let j be index such that Ak, and express your answer in terms of j Part 2 (5 points): Derive a general formula for ElXl (again in terms of j) Part 3 (5 points:) Use part 2 to figure out the expected running of Part 4 (5 point:) What is E[X if k is NOT in the array? Note that we can no longer define a j such that Au-k, because k not in the array. Think about how you want to define j instead, and make sure to be explicit in your solution about how you are defining j Note that in the analysis above, the algorithm doesnt actually know j. But thats ok because our analysis showed that no matter what j happens to be, the expected running time is O(insert your answer to part 3)" src="https://files.transtutors.com/cdn/qimg/6941962123ba43948099a4f2942aee4d.jpg" aria-describedby="aap"> Problem l: ftandom Binary Search (20 points total Consider the Following Problem: Input: a sorted array A of length n, and a target number k e Output: index i such that A = k, or no solution if none exists. Previously, we showed that binary search solves this problem in O(log(n)) time by repcatedly looking at the middle and recursing to one side. Let&#39;s say that instead of picking the middle element, we picked a random element in the array- Here is the pseudocode. Algorithm: RandomBinarySearch(A,k,left,right) – in the initial call left 0 and right-n-1 1. If left > righ 2.Rand(left….right) 3. If Alk return i If A>k t return “no solution . return RandomBinarySearch(A,k,left, i-1) 5. If All

"Get 15% discount on your first 3 orders with us"
Use the following coupon

Order Now