Category : binary-search

I was trying to execute the Binary Search program in python. I followed the algorithm steps yet it gives me this error. Here’s my code: def binarySearch(a,k,l,r): if l > r: return -1 else: mid = (l+(r-l))//2 if(a[mid]>k): return binarySearch(a,k,l,mid-1) elif(a[mid]<k): return binarySearch(a,k,mid+1,r) else: return mid t = int(input("Enter no. of test cases: ")) for ..

Read more

I am given a sorted array that has been shifted to the right by some amount. For example [45,61,71,72,73,0,1,21,33,37] ; which is [0,1,21,33,37,45,61,71,72,73] shifted to the right by 5 spaces. We are also given a target integer that may or may not be in the array. If it is in the array, we are asked ..

Read more