<s>
In	O
computer	O
science	O
,	O
a	O
range	B-Algorithm
minimum	I-Algorithm
query	I-Algorithm
(	O
RMQ	O
)	O
solves	O
the	O
problem	O
of	O
finding	O
the	O
minimal	O
value	O
in	O
a	O
sub-array	O
of	O
an	O
array	O
of	O
comparable	O
objects	O
.	O
</s>
<s>
Range	B-Algorithm
minimum	I-Algorithm
queries	I-Algorithm
have	O
several	O
use	O
cases	O
in	O
computer	O
science	O
,	O
such	O
as	O
the	O
lowest	O
common	O
ancestor	O
problem	O
and	O
the	O
longest	B-Data_Structure
common	I-Data_Structure
prefix	I-Data_Structure
problem	I-Data_Structure
(	O
LCP	O
)	O
.	O
</s>
<s>
Given	O
an	O
array	O
of	O
objects	O
taken	O
from	O
a	O
totally	O
ordered	O
set	O
,	O
such	O
as	O
integers	O
,	O
the	O
range	B-Algorithm
minimum	I-Algorithm
query	I-Algorithm
(	O
with	O
)	O
returns	O
the	O
position	O
of	O
the	O
minimal	O
element	O
in	O
the	O
specified	O
sub-array	O
.	O
</s>
<s>
For	O
example	O
,	O
when	O
,	O
then	O
the	O
answer	O
to	O
the	O
range	B-Algorithm
minimum	I-Algorithm
query	I-Algorithm
for	O
the	O
sub-array	O
is	O
,	O
as	O
.	O
</s>
<s>
the	O
minimum	O
of	O
all	O
sub-arrays	O
of	O
,	O
and	O
store	O
these	O
in	O
an	O
array	O
such	O
that	O
;	O
then	O
a	O
range	B-Algorithm
min	I-Algorithm
query	I-Algorithm
can	O
be	O
solved	O
in	O
constant	O
time	O
by	O
array	O
lookup	O
in	O
.	O
</s>
<s>
There	O
are	O
possible	O
queries	O
for	O
a	O
length	O
-	O
array	O
,	O
and	O
the	O
answers	O
to	O
these	O
can	O
be	O
computed	O
in	O
time	O
by	O
dynamic	B-Algorithm
programming	I-Algorithm
.	O
</s>
<s>
However	O
,	O
the	O
array	O
will	O
store	O
pre-computed	O
range	B-Algorithm
minimum	I-Algorithm
queries	I-Algorithm
not	O
for	O
every	O
range	O
,	O
but	O
only	O
for	O
ranges	O
whose	O
size	O
is	O
a	O
power	O
of	O
two	O
.	O
</s>
<s>
There	O
are	O
such	O
queries	O
for	O
each	O
start	O
position	O
,	O
so	O
the	O
size	O
of	O
the	O
dynamic	B-Algorithm
programming	I-Algorithm
table	O
is	O
.	O
</s>
<s>
Constant	O
time	O
is	O
achieved	O
by	O
storing	O
the	O
Cartesian	B-Algorithm
trees	I-Algorithm
for	O
all	O
the	O
blocks	O
in	O
the	O
array	O
.	O
</s>
<s>
To	O
look	O
up	O
results	O
efficiently	O
,	O
the	O
Cartesian	B-Algorithm
tree	I-Algorithm
(	O
row	O
)	O
corresponding	O
to	O
a	O
specific	O
block	O
must	O
be	O
addressable	O
in	O
constant	O
time	O
.	O
</s>
<s>
This	O
can	O
be	O
achieved	O
by	O
doing	O
a	O
breadth-first-search	O
through	O
the	O
tree	O
and	O
adding	O
leaf	O
nodes	O
so	O
that	O
every	O
existing	O
node	O
in	O
the	O
Cartesian	B-Algorithm
tree	I-Algorithm
has	O
exactly	O
two	O
children	O
.	O
</s>
<s>
RMQs	O
are	O
used	O
as	O
a	O
tool	O
for	O
many	O
tasks	O
in	O
exact	O
and	O
approximate	O
string	B-Algorithm
matching	I-Algorithm
.	O
</s>
<s>
RMQs	O
can	O
be	O
used	O
to	O
solve	O
the	O
lowest	O
common	O
ancestor	O
problem	O
and	O
are	O
used	O
as	O
a	O
tool	O
for	O
many	O
tasks	O
in	O
exact	O
and	O
approximate	O
string	B-Algorithm
matching	I-Algorithm
.	O
</s>
<s>
We	O
then	O
compute	O
the	O
LCP	B-Data_Structure
array	I-Data_Structure
giving	O
the	O
LCP	O
of	O
adjacent	O
suffixes	O
in	O
.	O
</s>
