# Algorithms # www.creationsitewebcasablanca.com # Binary search by a recursive algorithm. # Return the index to a value in an array, # or -1 if the value can not be found. # The contents of the table must be sorted in ascending order. # The array is a global variable to optimizes the speed. # The move is performed with the starting and ending indices. array A = [ 1, 3, 5, 8, 13, 24, 33, 46, 50, 51, 90, 980, 2000 ] int size = A.size() int val int binarySearch(int value, int starting, int ending) if ending < starting return -1 int mid = (starting + ending) / 2 if A[mid] = value return mid > value ending = mid - 1 < value starting = mid + 1 /if return binarySearch(value, starting, ending) A.display() input "Give a value to search:", val int y = binarySearch(int(val), 0, A.size() - 1) if y >= 0 print val, "is at position", y else print val, "not found in the array..." /if