<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
the	O
all	B-Operating_System
nearest	I-Operating_System
smaller	I-Operating_System
values	I-Operating_System
problem	O
is	O
the	O
following	O
task	O
:	O
for	O
each	O
position	O
in	O
a	O
sequence	O
of	O
numbers	O
,	O
search	O
among	O
the	O
previous	O
positions	O
for	O
the	O
last	O
position	O
that	O
contains	O
a	O
smaller	O
value	O
.	O
</s>
<s>
This	O
problem	O
can	O
be	O
solved	O
efficiently	O
both	O
by	O
parallel	O
and	O
non-parallel	O
algorithms	B-Operating_System
:	O
,	O
who	O
first	O
identified	O
the	O
procedure	O
as	O
a	O
useful	O
subroutine	O
for	O
other	O
parallel	O
programs	O
,	O
developed	O
efficient	O
algorithms	B-Operating_System
to	O
solve	O
it	O
in	O
the	O
Parallel	B-Operating_System
Random	I-Operating_System
Access	I-Operating_System
Machine	I-Operating_System
model	O
;	O
it	O
may	O
also	O
be	O
solved	O
in	O
linear	O
time	O
on	O
a	O
non-parallel	O
computer	O
using	O
a	O
stack-based	O
algorithm	O
.	O
</s>
<s>
Later	O
researchers	O
have	O
studied	O
algorithms	B-Operating_System
to	O
solve	O
it	O
in	O
other	O
models	O
of	O
parallel	O
computation	O
.	O
</s>
<s>
Merge	B-Algorithm
algorithms	I-Algorithm
,	O
computing	O
the	O
merge	O
step	O
of	O
a	O
merge	B-Algorithm
sort	I-Algorithm
.	O
</s>
<s>
The	O
input	O
to	O
these	O
algorithms	B-Operating_System
consists	O
of	O
two	O
sorted	O
arrays	O
of	O
numbers	O
;	O
the	O
desired	O
output	O
is	O
the	O
same	O
set	O
of	O
numbers	O
in	O
a	O
single	O
sorted	O
array	B-Data_Structure
.	O
</s>
<s>
If	O
one	O
concatenates	O
the	O
two	O
sorted	O
arrays	O
,	O
the	O
first	O
in	O
ascending	O
order	O
and	O
the	O
second	O
in	O
descending	O
order	O
,	O
then	O
the	O
predecessor	O
of	O
each	O
value	O
in	O
the	O
output	O
is	O
either	O
its	O
closest	O
previous	O
smaller	O
value	O
or	O
its	O
closest	O
following	O
smaller	O
value	O
(	O
whichever	O
of	O
the	O
two	O
is	O
larger	O
)	O
,	O
and	O
the	O
position	O
of	O
each	O
value	O
in	O
the	O
sorted	O
output	O
array	B-Data_Structure
may	O
easily	O
be	O
calculated	O
from	O
the	O
positions	O
of	O
these	O
two	O
nearest	O
smaller	O
values	O
.	O
</s>
<s>
Construction	O
of	O
Cartesian	B-Algorithm
trees	I-Algorithm
.	O
</s>
<s>
A	O
Cartesian	B-Algorithm
tree	I-Algorithm
is	O
a	O
data	B-General_Concept
structure	I-General_Concept
introduced	O
by	O
and	O
further	O
studied	O
by	O
for	O
range	B-Data_Structure
searching	I-Data_Structure
applications	O
.	O
</s>
<s>
Cartesian	B-Algorithm
trees	I-Algorithm
also	O
arise	O
in	O
the	O
definition	O
of	O
the	O
treap	B-Application
and	O
randomized	B-Application
binary	I-Application
search	I-Application
tree	I-Application
data	B-General_Concept
structures	I-General_Concept
for	O
binary	O
searching	O
.	O
</s>
<s>
The	O
Cartesian	B-Algorithm
tree	I-Algorithm
of	O
a	O
sequence	O
of	O
values	O
has	O
a	O
node	O
for	O
each	O
value	O
.	O
</s>
<s>
Thus	O
,	O
Cartesian	B-Algorithm
trees	I-Algorithm
may	O
be	O
constructed	O
in	O
linear	O
time	O
based	O
on	O
an	O
all	B-Operating_System
nearest	I-Operating_System
smaller	I-Operating_System
values	I-Operating_System
algorithm	O
.	O
</s>
<s>
If	O
a	O
sequence	O
of	O
open	O
and	O
close	O
parenthesis	O
characters	O
is	O
given	O
as	O
input	O
,	O
together	O
with	O
the	O
nesting	O
depth	O
of	O
each	O
parenthesis	O
,	O
then	O
the	O
match	O
to	O
each	O
open	O
parenthesis	O
is	O
the	O
next	O
close	O
parenthesis	O
with	O
no	O
larger	O
nesting	O
depth	O
,	O
so	O
it	O
can	O
be	O
found	O
by	O
an	O
all	B-Operating_System
nearest	I-Operating_System
smaller	I-Operating_System
values	I-Operating_System
computation	O
that	O
breaks	O
ties	O
in	O
favor	O
of	O
close	O
parentheses	O
.	O
</s>
<s>
If	O
the	O
nesting	O
depths	O
are	O
not	O
given	O
,	O
they	O
can	O
be	O
calculated	O
using	O
a	O
prefix	B-Application
sum	I-Application
computation	O
.	O
</s>
<s>
Similar	O
techniques	O
may	O
also	O
be	O
applied	O
to	O
problems	O
of	O
polygon	B-Algorithm
triangulation	I-Algorithm
,	O
convex	O
hull	O
construction	O
(	O
parallelizing	O
the	O
sequential	O
Graham	B-Algorithm
scan	I-Algorithm
convex	O
hull	O
algorithm	O
)	O
,	O
reconstruction	O
of	O
trees	O
from	O
two	O
of	O
the	O
trees	O
 '	O
traversal	O
orderings	O
,	O
and	O
quadtree	O
construction	O
.	O
</s>
<s>
On	O
a	O
sequential	O
computer	O
,	O
all	B-Operating_System
nearest	I-Operating_System
smaller	I-Operating_System
values	I-Operating_System
may	O
be	O
found	O
by	O
using	O
a	O
stack	B-Application
data	I-Application
structure	I-Application
:	O
one	O
processes	O
the	O
values	O
in	O
sequence	O
order	O
,	O
using	O
the	O
stack	B-Application
to	O
maintain	O
a	O
subsequence	O
of	O
the	O
values	O
that	O
have	O
been	O
processed	O
so	O
far	O
and	O
are	O
smaller	O
than	O
any	O
later	O
value	O
that	O
has	O
already	O
been	O
processed	O
.	O
</s>
<s>
In	O
pseudocode	B-Language
,	O
the	O
algorithm	O
is	O
as	O
follows	O
.	O
</s>
<s>
It	O
is	O
closely	O
related	O
to	O
an	O
algorithm	O
of	O
Knuth	O
for	O
sorting	B-Algorithm
with	I-Algorithm
a	I-Algorithm
stack	I-Algorithm
(	O
for	O
inputs	O
that	O
can	O
be	O
sorted	O
in	O
this	O
way	O
)	O
.	O
</s>
<s>
An	O
even	O
simpler	O
linear-time	O
sequential	O
algorithm	O
(	O
,	O
Lemma	O
1	O
)	O
does	O
not	O
even	O
need	O
a	O
stack	B-Application
;	O
it	O
assumes	O
that	O
the	O
input	O
sequence	O
is	O
given	O
as	O
an	O
array	B-Data_Structure
A[1,n]	O
of	O
size	O
n	O
,	O
and	O
stores	O
the	O
index	O
j	O
of	O
the	O
preceding	O
smaller	O
value	O
of	O
the	O
ith	O
value	O
A[i]	O
in	O
P[i]	O
.	O
</s>
<s>
showed	O
how	O
to	O
solve	O
the	O
all	B-Operating_System
nearest	I-Operating_System
smaller	I-Operating_System
values	I-Operating_System
problem	O
efficiently	O
on	O
a	O
concurrent-read	O
concurrent-write	O
Parallel	B-Operating_System
Random	I-Operating_System
Access	I-Operating_System
Machine	I-Operating_System
.	O
</s>
<s>
For	O
a	O
sequence	O
of	O
n	O
values	O
,	O
stored	O
as	O
an	O
array	B-Data_Structure
,	O
they	O
show	O
that	O
the	O
problem	O
may	O
be	O
solved	O
in	O
time	O
O(loglogn )	O
using	O
a	O
linear	O
amount	O
of	O
total	O
work	O
.	O
</s>
<s>
Since	O
this	O
work	O
,	O
parallel	B-Operating_System
algorithms	I-Operating_System
for	O
the	O
all	B-Operating_System
nearest	I-Operating_System
smaller	I-Operating_System
values	I-Operating_System
problem	O
have	O
also	O
been	O
developed	O
on	O
other	O
models	O
of	O
parallel	O
computation	O
,	O
including	O
parallel	O
computers	O
with	O
a	O
hypercube-structured	O
communications	O
network	O
,	O
and	O
the	O
bulk	B-Application
synchronous	I-Application
parallel	I-Application
model	O
.	O
</s>
