Exponential Search
Another alternative to variable size decrease-and-conquer search is known as exponential search. This algorithm begins searching at the beginning of the list. It then progressively tests at larger intervals (A[2],A[4],A[8], . . .) until a straddling range is found which may contain the search value. A binary search is then performed on only the suspect range to ?nd the ?nal index position.
ALGORITHM ExponentialSearch (A[0 . . . n - 1], k)
// A variable-size decrease and conquer search in an ordered list.// INPUT : An array A[0 . . . n - 1] of ordered elements, and a search key k.// OUTPUT : an index to the position of k in A if k is found or -1 otherwise.1: set pos ← 22: while pos < n and A[pos] < k do3: prev ← pos4: pos ← pos 25: if pos > n - 1 then6: pos ← n - 17: result ← BinarySearch(A[prev . . . pos], k)8: if result = -1 then9: return -110: else11: return result + prev
Algorithm ExponentialSearch shows the pseudocode for this solution. Implement the algorithm.