2019 C/CS4: A Search Algorithm
Source:
January 27, 2019
search2019computer sciencealgorithm
Problem Statement
Define a search algorithm called . Throughout, assume is a 1-indexed sorted array of distinct integers. To search for an integer in this array, we search the indices until we either reach the end of the array or . If at any point we get we stop and return . Once we have , we throw away the first elements of , and recursively search in the same fashion. For example, for an integer which is at position we will search the locations .Define to be a function which returns how many (not necessarily distinct) indices we look at when calling with an integer at position in . For example, . If has length , find