Skip to main content

Interpolation Search

Definition​

Interpolation Search is an efficient searching algorithm that works on sorted arrays. It improves on binary search by using interpolation to find the probable position of the target value

Practice​

interpolationSearch(arr, x):
low = 0
high = length(arr) - 1

while low <= high and x >= arr[low] and x <= arr[high]:
pos = low + ((high - low) / (arr[high] - arr[low])) * (x - arr[low])

if arr[pos] == x:
return pos
elif arr[pos] < x:
low = pos + 1
else:
high = pos - 1

return -1