Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does list length reduce to sqrt(n) after each comparison in interpolation search?

According to the book I'm reading, interpolation search takes O(loglogn) in average case.
The book assumes that each compare reduce the length of the list from n to sqrt(n). Well, it isn't difficult to work out the O(loglogn) given this assumption.
However, the book didn't talk more about this assumption except that it says this is correct.

Question: can anyone give some explanation on why this is true?

like image 721
Haozhun Avatar asked Feb 05 '11 03:02

Haozhun


1 Answers

It depends on the input being uniformly distributed (without such an assumption, O(log n) is the best you can do theoretically, ie binary search is optimal). With a uniform distribution, the variance is around sqrt(n), and in the expected case each iteration hits within the variance of the target. Thus, as you say, the search space goes from n -> sqrt(n) on each iteration.

like image 100
Raph Levien Avatar answered Nov 15 '22 22:11

Raph Levien