Question: Consider the Following Problem: Input: a sorted array A of length n, and a target number k Output: index i such that A[i] = k,

 Consider the Following Problem: Input: a sorted array A of lengthn, and a target number k Output: index i such that A[i]

Consider the Following Problem: Input: a sorted array A of length n, and a target number k Output: index i such that A[i] = k, or no solution if none exists. Previously, we showed that binary search solves this problem in O(log(n)) time by repeatedly looking at the middle and recursing to one side. Let's say that instead of picking the middle element, we picked a random element in e array. Here is the pseudocode. Algorithm: RandomBinarySearch(A,k,left,right) in the initial call, left 0 and right n-1 1. If left > right return "no solution" 2. Rand(left....right) 3. If Alik returni 4. If Ai>k . return RandomBinarySearch(A,k,left, i-1) 5. If Ali right return "no solution" 2. Rand(left....right) 3. If Alik returni 4. If Ai>k . return RandomBinarySearch(A,k,left, i-1) 5. If Ali

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!