Interpolation Search
The next task is to implement a variable size decrease-and-conquer solution to search. See Levitin [2007] pp 190 for a detailed description of the interpolation search algorithm.
ALGORITHM InterpolationSearch (A[0 . . . n - 1], k)// A variable-sized 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: l ← 0; r ← n - 12: while A[l] < k and A[r] ≥ k do3: m ← l + (k-A[l])·(r-l)A[r]-A[l]4: if A[m] < k then5: l ← m+ 16: else if A[m] > k then7: r ← m- 18: else9: return m10: if A[l] = k then11: return l12: else13: return -1
Algorithm InterpolationSearch shows the pseudocode for this solution. Implement the algorithm.