SearchingAnimated
Interpolation Search
Guess the position from the value, like looking up a name in a phone book.
Time
O(log log n) avg, O(n) worst
Extra space
O(1)
Use it for
Sorted, evenly distributed numbers.
How it works
- Works best on sorted numbers that are spread evenly.
- Instead of the middle, guess where the target should be: pos = low + (x − a[low]) · (high − low) / (a[high] − a[low]).
- Compare a[pos] with the target and shrink the window as in binary search.
- On evenly spread data it needs about log log n steps; on skewed data it can degrade to n.
Watch it run
Loading animation…