Course Solutions Uncategorized (Solved) : Consider Following Problem Input Sorted Array Length N Target Number K Output Index K Solu Q32730643 . . . .

(Solved) : Consider Following Problem Input Sorted Array Length N Target Number K Output Index K Solu Q32730643 . . . .

 

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

OR

PayPal Gateway not configured

OR

PayPal Gateway not configured

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post