<s>
Interpolation	B-Algorithm
search	I-Algorithm
is	O
an	O
algorithm	O
for	O
searching	B-Application
for	O
a	O
key	O
in	O
an	O
array	B-Data_Structure
that	O
has	O
been	O
ordered	O
by	O
numerical	O
values	O
assigned	O
to	O
the	O
keys	O
(	O
key	O
values	O
)	O
.	O
</s>
<s>
Interpolation	B-Algorithm
search	I-Algorithm
resembles	O
the	O
method	O
by	O
which	O
people	O
search	O
a	O
telephone	O
directory	O
for	O
a	O
name	O
(	O
the	O
key	O
value	O
by	O
which	O
the	O
book	O
's	O
entries	O
are	O
ordered	O
)	O
:	O
in	O
each	O
step	O
the	O
algorithm	O
calculates	O
where	O
in	O
the	O
remaining	O
search	O
space	O
the	O
sought	O
item	O
might	O
be	O
,	O
based	O
on	O
the	O
key	O
values	O
at	O
the	O
bounds	O
of	O
the	O
search	O
space	O
and	O
the	O
value	O
of	O
the	O
sought	O
key	O
,	O
usually	O
via	O
a	O
linear	O
interpolation	O
.	O
</s>
<s>
The	O
linear	B-Algorithm
search	I-Algorithm
uses	O
equality	O
only	O
as	O
it	O
compares	O
elements	O
one-by-one	O
from	O
the	O
start	O
,	O
ignoring	O
any	O
sorting	B-Algorithm
.	O
</s>
<s>
On	O
average	O
the	O
interpolation	B-Algorithm
search	I-Algorithm
makes	O
about	O
log(log(n )	O
)	O
comparisons	O
(	O
if	O
the	O
elements	O
are	O
uniformly	O
distributed	O
)	O
,	O
where	O
n	O
is	O
the	O
number	O
of	O
elements	O
to	O
be	O
searched	O
.	O
</s>
<s>
In	O
interpolation-sequential	O
search	O
,	O
interpolation	O
is	O
used	O
to	O
find	O
an	O
item	O
near	O
the	O
one	O
being	O
searched	O
for	O
,	O
then	O
linear	B-Algorithm
search	I-Algorithm
is	O
used	O
to	O
find	O
the	O
exact	O
item	O
.	O
</s>
<s>
However	O
,	O
Dynamic	O
Interpolation	B-Algorithm
Search	I-Algorithm
is	O
possible	O
in	O
o(log log n )	O
time	O
using	O
a	O
novel	O
data	O
structure	O
.	O
</s>
<s>
Practical	O
performance	O
of	O
interpolation	B-Algorithm
search	I-Algorithm
depends	O
on	O
whether	O
the	O
reduced	O
number	O
of	O
probes	O
is	O
outweighed	O
by	O
the	O
more	O
complicated	O
calculations	O
needed	O
for	O
each	O
probe	O
.	O
</s>
<s>
Index	O
structures	O
like	O
B-trees	B-Architecture
also	O
reduce	O
the	O
number	O
of	O
disk	O
accesses	O
,	O
and	O
are	O
more	O
often	O
used	O
to	O
index	O
on-disk	O
data	O
in	O
part	O
because	O
they	O
can	O
index	O
many	O
types	O
of	O
data	O
and	O
can	O
be	O
updated	O
online	B-Algorithm
.	O
</s>
<s>
Still	O
,	O
interpolation	B-Algorithm
search	I-Algorithm
may	O
be	O
useful	O
when	O
one	O
is	O
forced	O
to	O
search	O
certain	O
sorted	O
but	O
unindexed	O
on-disk	O
datasets	O
.	O
</s>
<s>
On	O
the	O
other	O
hand	O
,	O
for	O
a	O
phone	O
book	O
sorted	O
by	O
name	O
,	O
the	O
straightforward	O
approach	O
to	O
interpolation	B-Algorithm
search	I-Algorithm
does	O
not	O
apply	O
.	O
</s>
<s>
Some	O
interpolation	B-Algorithm
search	I-Algorithm
implementations	O
may	O
not	O
work	O
as	O
expected	O
when	O
a	O
run	O
of	O
equal	O
key	O
values	O
exists	O
.	O
</s>
<s>
The	O
simplest	O
implementation	O
of	O
interpolation	B-Algorithm
search	I-Algorithm
wo	O
n't	O
necessarily	O
select	O
the	O
first	O
(	O
or	O
last	O
)	O
element	O
of	O
such	O
a	O
run	O
.	O
</s>
<s>
The	O
conversion	O
of	O
names	O
in	O
a	O
telephone	O
book	O
to	O
some	O
sort	O
of	O
number	O
clearly	O
will	O
not	O
provide	O
numbers	O
having	O
a	O
uniform	O
distribution	O
(	O
except	O
via	O
immense	O
effort	O
such	O
as	O
sorting	B-Algorithm
the	O
names	O
and	O
calling	O
them	O
name	O
#1	O
,	O
name	O
#2	O
,	O
etc	O
.	O
)	O
</s>
<s>
The	O
following	O
C++	B-Language
code	I-Language
example	O
is	O
a	O
simple	O
implementation	O
.	O
</s>
<s>
Each	O
iteration	O
of	O
the	O
above	O
code	O
requires	O
between	O
five	O
and	O
six	O
comparisons	O
(	O
the	O
extra	O
is	O
due	O
to	O
the	O
repetitions	O
needed	O
to	O
distinguish	O
the	O
three	O
states	O
of	O
< >	O
and	O
=	O
via	O
binary	O
comparisons	O
in	O
the	O
absence	O
of	O
a	O
three-way	O
comparison	O
)	O
plus	O
some	O
messy	O
arithmetic	O
,	O
while	O
the	O
binary	O
search	B-Application
algorithm	I-Application
can	O
be	O
written	O
with	O
one	O
comparison	O
per	O
iteration	O
and	O
uses	O
only	O
trivial	O
integer	O
arithmetic	O
.	O
</s>
<s>
It	O
would	O
thereby	O
search	O
an	O
array	B-Data_Structure
of	O
a	O
million	O
elements	O
with	O
no	O
more	O
than	O
twenty	O
comparisons	O
(	O
involving	O
accesses	O
to	O
slow	O
memory	O
where	O
the	O
array	B-Data_Structure
elements	I-Data_Structure
are	O
stored	O
)	O
;	O
to	O
beat	O
that	O
,	O
the	O
interpolation	B-Algorithm
search	I-Algorithm
,	O
as	O
written	O
above	O
,	O
would	O
be	O
allowed	O
no	O
more	O
than	O
three	O
iterations	O
.	O
</s>
