# Algorithms # www.scriptol.com # Recursive binary search algorithm on an array of strings. # Returns the index of an element in the array, # or -1 if the string can not be found. # The string must be sorted in ascending order in the array. # The array is a global variable, that optimizes speed. # The move is performed by the starting and ending indices. array A = [ "alpha", "ariana", "beta", "bridget", "delphina", "delta", "omega", "orwell", "pi", "ro", "rosana" ] int size = A.size() text val int binarySearch(text value, int starting, int ending) if ending < starting return -1 int mid = (starting + ending) / 2 int result = strcmp(value, A[mid]) if result = 0 return mid < 0 ending = mid - 1 > 0 starting = mid + 1 /if return binarySearch(value, starting, ending) A.display() input "Give a word to search:", val int y = binarySearch(val, 0, A.size() - 1) if y >= 0 print val, "is at position", y else print val, "not found in the array..." /if