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 noneexists.
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. i ← Rand(left….right)
3. If A[i] = k return i
4. IfA[i]>k
• return RandomBinarySearch(A,k,left, i-1)
5. IfA[i]
• RandomBinarySearch(A,k,i+1,right)
In this question, we will figure out the expected running timeof this RandomBinarySearch. Note that all the work done by thealgorithm consists of comparing some A[i] to k (and then recursingand comparing some otherA[i] to
PayPal Gateway not configured
PayPal Gateway not configured