<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
a	O
priority	B-Application
queue	I-Application
is	O
an	O
abstract	O
data-type	O
similar	O
to	O
a	O
regular	O
queue	B-Application
or	O
stack	B-Application
data	I-Application
structure	I-Application
.	O
</s>
<s>
Each	O
element	O
in	O
a	O
priority	B-Application
queue	I-Application
has	O
an	O
associated	O
priority	O
.	O
</s>
<s>
In	O
a	O
priority	B-Application
queue	I-Application
,	O
elements	O
with	O
high	O
priority	O
are	O
served	O
before	O
elements	O
with	O
low	O
priority	O
.	O
</s>
<s>
While	O
priority	B-Application
queues	I-Application
are	O
often	O
implemented	O
using	O
heaps	B-Application
,	O
they	O
are	O
conceptually	O
distinct	O
from	O
heaps	B-Application
.	O
</s>
<s>
A	O
priority	B-Application
queue	I-Application
is	O
an	O
abstract	O
data	B-General_Concept
structure	I-General_Concept
like	O
a	O
list	O
or	O
a	O
map	B-Application
;	O
just	O
as	O
a	O
list	O
can	O
be	O
implemented	O
with	O
a	O
linked	B-Data_Structure
list	I-Data_Structure
or	O
with	O
an	O
array	B-Data_Structure
,	O
a	O
priority	B-Application
queue	I-Application
can	O
be	O
implemented	O
with	O
a	O
heap	B-Application
or	O
another	O
method	O
such	O
as	O
an	O
unordered	O
array	B-Data_Structure
.	O
</s>
<s>
A	O
priority	B-Application
queue	I-Application
must	O
at	O
least	O
support	O
the	O
following	O
operations	O
:	O
</s>
<s>
is_empty	O
:	O
check	O
whether	O
the	O
queue	B-Application
has	O
no	O
elements	O
.	O
</s>
<s>
insert_with_priority	O
:	O
add	O
an	O
element	O
to	O
the	O
queue	B-Application
with	O
an	O
associated	O
priority	O
.	O
</s>
<s>
pull_highest_priority_element	O
:	O
remove	O
the	O
element	O
from	O
the	O
queue	B-Application
that	O
has	O
the	O
highest	O
priority	O
,	O
and	O
return	O
it	O
.	O
</s>
<s>
In	O
addition	O
,	O
peek	B-Application
(	O
in	O
this	O
context	O
often	O
called	O
find-max	O
or	O
find-min	O
)	O
,	O
which	O
returns	O
the	O
highest-priority	O
element	O
but	O
does	O
not	O
modify	O
the	O
queue	B-Application
,	O
is	O
very	O
frequently	O
implemented	O
,	O
and	O
nearly	O
always	O
executes	O
in	O
O(1 )	O
time	O
.	O
</s>
<s>
This	O
operation	O
and	O
its	O
O(1 )	O
performance	O
is	O
crucial	O
to	O
many	O
applications	O
of	O
priority	B-Application
queues	I-Application
.	O
</s>
<s>
More	O
advanced	O
implementations	O
may	O
support	O
more	O
complicated	O
operations	O
,	O
such	O
as	O
pull_lowest_priority_element	O
,	O
inspecting	O
the	O
first	O
few	O
highest	O
-	O
or	O
lowest-priority	O
elements	O
,	O
clearing	O
the	O
queue	B-Application
,	O
clearing	O
subsets	O
of	O
the	O
queue	B-Application
,	O
performing	O
a	O
batch	O
insert	O
,	O
merging	O
two	O
or	O
more	O
queues	B-Application
into	O
one	O
,	O
incrementing	O
priority	O
of	O
any	O
element	O
,	O
etc	O
.	O
</s>
<s>
Stacks	B-Application
and	O
queues	B-Application
can	O
be	O
implemented	O
as	O
particular	O
kinds	O
of	O
priority	B-Application
queues	I-Application
,	O
with	O
the	O
priority	O
determined	O
by	O
the	O
order	O
in	O
which	O
the	O
elements	O
are	O
inserted	O
.	O
</s>
<s>
In	O
a	O
stack	B-Application
,	O
the	O
priority	O
of	O
each	O
inserted	O
element	O
is	O
monotonically	O
increasing	O
;	O
thus	O
,	O
the	O
last	O
element	O
inserted	O
is	O
always	O
the	O
first	O
retrieved	O
.	O
</s>
<s>
In	O
a	O
queue	B-Application
,	O
the	O
priority	O
of	O
each	O
inserted	O
element	O
is	O
monotonically	O
decreasing	O
;	O
thus	O
,	O
the	O
first	O
element	O
inserted	O
is	O
always	O
the	O
first	O
retrieved	O
.	O
</s>
<s>
There	O
are	O
a	O
variety	O
of	O
simple	O
,	O
usually	O
inefficient	O
,	O
ways	O
to	O
implement	O
a	O
priority	B-Application
queue	I-Application
.	O
</s>
<s>
They	O
provide	O
an	O
analogy	O
to	O
help	O
one	O
understand	O
what	O
a	O
priority	B-Application
queue	I-Application
is	O
.	O
</s>
<s>
For	O
instance	O
,	O
one	O
can	O
keep	O
all	O
the	O
elements	O
in	O
an	O
unsorted	B-Algorithm
list	I-Algorithm
(O(1 )	O
insertion	O
time	O
)	O
.	O
</s>
<s>
In	O
another	O
case	O
,	O
one	O
can	O
keep	O
all	O
the	O
elements	O
in	O
a	O
priority	O
sorted	B-Algorithm
list	I-Algorithm
(O(n )	O
insertion	B-Algorithm
sort	I-Algorithm
time	O
)	O
,	O
whenever	O
the	O
highest-priority	O
element	O
is	O
requested	O
,	O
the	O
first	O
one	O
in	O
the	O
list	O
can	O
be	O
returned	O
.	O
</s>
<s>
To	O
improve	O
performance	O
,	O
priority	B-Application
queues	I-Application
are	O
typically	O
based	O
on	O
a	O
heap	B-Application
,	O
giving	O
O(log n )	O
performance	O
for	O
inserts	O
and	O
removals	O
,	O
and	O
O(n )	O
to	O
build	O
the	O
heap	B-Application
initially	O
from	O
a	O
set	O
of	O
n	O
elements	O
.	O
</s>
<s>
Variants	O
of	O
the	O
basic	O
heap	B-Application
data	I-Application
structure	I-Application
such	O
as	O
pairing	B-Application
heaps	I-Application
or	O
Fibonacci	B-Application
heaps	I-Application
can	O
provide	O
better	O
bounds	O
for	O
some	O
operations	O
.	O
</s>
<s>
Alternatively	O
,	O
when	O
a	O
self-balancing	B-Data_Structure
binary	I-Data_Structure
search	I-Data_Structure
tree	I-Data_Structure
is	O
used	O
,	O
insertion	O
and	O
removal	O
also	O
take	O
O(log n )	O
time	O
,	O
although	O
building	O
trees	O
from	O
existing	O
sequences	O
of	O
elements	O
takes	O
O(n log n )	O
time	O
;	O
this	O
is	O
typical	O
where	O
one	O
might	O
already	O
have	O
access	O
to	O
these	O
data	B-General_Concept
structures	I-General_Concept
,	O
such	O
as	O
with	O
third-party	O
or	O
standard	O
libraries	O
.	O
</s>
<s>
From	O
a	O
space-complexity	O
standpoint	O
,	O
using	O
self-balancing	B-Data_Structure
binary	I-Data_Structure
search	I-Data_Structure
tree	I-Data_Structure
with	O
linked	B-Data_Structure
list	I-Data_Structure
takes	O
more	O
storage	O
,	O
since	O
it	O
requires	O
to	O
store	O
extra	O
references	O
to	O
other	O
nodes	O
.	O
</s>
<s>
From	O
a	O
computational-complexity	O
standpoint	O
,	O
priority	B-Application
queues	I-Application
are	O
congruent	O
to	O
sorting	B-Algorithm
algorithms	I-Algorithm
.	O
</s>
<s>
The	O
section	O
on	O
the	O
equivalence	O
of	O
priority	B-Application
queues	I-Application
and	O
sorting	B-Algorithm
algorithms	I-Algorithm
,	O
below	O
,	O
describes	O
how	O
efficient	O
sorting	B-Algorithm
algorithms	I-Algorithm
can	O
create	O
efficient	O
priority	B-Application
queues	I-Application
.	O
</s>
<s>
There	O
are	O
several	O
specialized	O
heap	B-Application
data	I-Application
structures	I-Application
that	O
either	O
supply	O
additional	O
operations	O
or	O
outperform	O
heap-based	O
implementations	O
for	O
specific	O
types	O
of	O
keys	O
,	O
specifically	O
integer	O
keys	O
.	O
</s>
<s>
When	O
only	O
insert	O
,	O
find-min	O
and	O
extract-min	O
are	O
needed	O
and	O
in	O
case	O
of	O
integer	O
priorities	O
,	O
a	O
bucket	B-Application
queue	I-Application
can	O
be	O
constructed	O
as	O
an	O
array	B-Data_Structure
of	O
linked	B-Data_Structure
lists	I-Data_Structure
plus	O
a	O
pointer	O
,	O
initially	O
.	O
</s>
<s>
These	O
queues	B-Application
are	O
useful	O
for	O
sorting	B-Algorithm
the	O
vertices	O
of	O
a	O
graph	O
by	O
their	O
degree	O
.	O
</s>
<s>
A	O
van	B-Application
Emde	I-Application
Boas	I-Application
tree	I-Application
supports	O
the	O
minimum	O
,	O
maximum	O
,	O
insert	O
,	O
delete	O
,	O
search	O
,	O
extract-min	O
,	O
extract-max	O
,	O
predecessor	O
and	O
successor ]	O
operations	O
in	O
O(log log C )	O
time	O
,	O
but	O
has	O
a	O
space	O
cost	O
for	O
small	O
queues	B-Application
of	O
about	O
O( 	O
2m/2	O
)	O
,	O
where	O
m	O
is	O
the	O
number	O
of	O
bits	O
in	O
the	O
priority	O
value	O
.	O
</s>
<s>
The	O
Fusion	B-Data_Structure
tree	I-Data_Structure
by	O
Fredman	O
and	O
Willard	O
implements	O
the	O
minimum	O
operation	O
in	O
O(1 )	O
time	O
and	O
insert	O
and	O
extract-min	O
operations	O
in	O
time	O
.	O
</s>
<s>
For	O
applications	O
that	O
do	O
many	O
"	O
peek	B-Application
"	O
operations	O
for	O
every	O
"	O
extract-min	O
"	O
operation	O
,	O
the	O
time	O
complexity	O
for	O
peek	B-Application
actions	O
can	O
be	O
reduced	O
to	O
O(1 )	O
in	O
all	O
tree	O
and	O
heap	B-Application
implementations	O
by	O
caching	O
the	O
highest	O
priority	O
element	O
after	O
every	O
insertion	O
and	O
removal	O
.	O
</s>
<s>
For	O
deletion	O
,	O
this	O
at	O
most	O
adds	O
an	O
additional	O
"	O
peek	B-Application
"	O
cost	O
,	O
which	O
is	O
typically	O
cheaper	O
than	O
the	O
deletion	O
cost	O
,	O
so	O
overall	O
time	O
complexity	O
is	O
not	O
significantly	O
impacted	O
.	O
</s>
<s>
Monotone	B-Application
priority	I-Application
queues	I-Application
are	O
specialized	O
queues	B-Application
that	O
are	O
optimized	O
for	O
the	O
case	O
where	O
no	O
item	O
is	O
ever	O
inserted	O
that	O
has	O
a	O
lower	O
priority	O
(	O
in	O
the	O
case	O
of	O
min-heap	B-Application
)	O
than	O
any	O
item	O
previously	O
extracted	O
.	O
</s>
<s>
This	O
restriction	O
is	O
met	O
by	O
several	O
practical	O
applications	O
of	O
priority	B-Application
queues	I-Application
.	O
</s>
<s>
The	O
semantics	O
of	O
priority	B-Application
queues	I-Application
naturally	O
suggest	O
a	O
sorting	B-Algorithm
method	O
:	O
insert	O
all	O
the	O
elements	O
to	O
be	O
sorted	O
into	O
a	O
priority	B-Application
queue	I-Application
,	O
and	O
sequentially	O
remove	O
them	O
;	O
they	O
will	O
come	O
out	O
in	O
sorted	O
order	O
.	O
</s>
<s>
This	O
is	O
actually	O
the	O
procedure	O
used	O
by	O
several	O
sorting	B-Algorithm
algorithms	I-Algorithm
,	O
once	O
the	O
layer	O
of	O
abstraction	B-Application
provided	O
by	O
the	O
priority	B-Application
queue	I-Application
is	O
removed	O
.	O
</s>
<s>
This	O
sorting	B-Algorithm
method	O
is	O
equivalent	O
to	O
the	O
following	O
sorting	B-Algorithm
algorithms	I-Algorithm
:	O
</s>
<s>
A	O
sorting	B-Algorithm
algorithm	I-Algorithm
can	O
also	O
be	O
used	O
to	O
implement	O
a	O
priority	B-Application
queue	I-Application
.	O
</s>
<s>
We	O
present	O
a	O
general	O
deterministic	O
linear	O
space	O
reduction	O
from	O
priority	B-Application
queues	I-Application
to	O
sorting	B-Algorithm
implying	O
that	O
if	O
we	O
can	O
sort	O
up	O
to	O
n	O
keys	O
in	O
S(n )	O
time	O
per	O
key	O
,	O
then	O
there	O
is	O
a	O
priority	B-Application
queue	I-Application
supporting	O
delete	O
and	O
insert	O
in	O
O(S(n )	O
)	O
time	O
and	O
find-min	O
in	O
constant	O
time	O
.	O
</s>
<s>
That	O
is	O
,	O
if	O
there	O
is	O
a	O
sorting	B-Algorithm
algorithm	I-Algorithm
which	O
can	O
sort	O
in	O
O(S )	O
time	O
per	O
key	O
,	O
where	O
S	O
is	O
some	O
function	O
of	O
n	O
and	O
word	O
size	O
,	O
then	O
one	O
can	O
use	O
the	O
given	O
procedure	O
to	O
create	O
a	O
priority	B-Application
queue	I-Application
where	O
pulling	O
the	O
highest-priority	O
element	O
is	O
O(1 )	O
time	O
,	O
and	O
inserting	O
new	O
elements	O
(	O
and	O
deleting	O
elements	O
)	O
is	O
O(S )	O
time	O
.	O
</s>
<s>
For	O
example	O
,	O
if	O
one	O
has	O
an	O
O(nlogn )	O
sort	B-Algorithm
algorithm	I-Algorithm
,	O
one	O
can	O
create	O
a	O
priority	B-Application
queue	I-Application
with	O
O(1 )	O
pulling	O
and	O
O(logn )	O
insertion	O
.	O
</s>
<s>
A	O
priority	B-Application
queue	I-Application
is	O
often	O
considered	O
to	O
be	O
a	O
"	O
container	B-Application
data	I-Application
structure	I-Application
"	O
.	O
</s>
<s>
The	O
Standard	B-Application
Template	I-Application
Library	I-Application
(	O
STL	O
)	O
,	O
and	O
the	O
C++	B-Language
1998	O
standard	O
,	O
specifies	O
as	O
one	O
of	O
the	O
STL	O
container	B-Application
adaptor	O
class	O
templates	B-Application
.	O
</s>
<s>
However	O
,	O
it	O
does	O
not	O
specify	O
how	O
two	O
elements	O
with	O
same	O
priority	O
should	O
be	O
served	O
,	O
and	O
indeed	O
,	O
common	O
implementations	O
will	O
not	O
return	O
them	O
according	O
to	O
their	O
order	O
in	O
the	O
queue	B-Application
.	O
</s>
<s>
It	O
implements	O
a	O
max-priority-queue	O
,	O
and	O
has	O
three	O
parameters	O
:	O
a	O
comparison	O
object	O
for	O
sorting	B-Algorithm
such	O
as	O
a	O
function	O
object	O
(	O
defaults	O
to	O
lessxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1	O
)	O
,	O
and	O
two	O
iterators	O
to	O
the	O
beginning	O
and	O
end	O
of	O
a	O
sequence	O
.	O
</s>
<s>
Unlike	O
actual	O
STL	O
containers	B-Application
,	O
it	O
does	O
not	O
allow	O
iteration	O
of	O
its	O
elements	O
(	O
it	O
strictly	O
adheres	O
to	O
its	O
abstract	O
data	O
type	O
definition	O
)	O
.	O
</s>
<s>
STL	O
also	O
has	O
utility	O
functions	O
for	O
manipulating	O
another	O
random-access	O
container	B-Application
as	O
a	O
binary	O
max-heap	B-Application
.	O
</s>
<s>
The	O
Boost	B-Language
libraries	I-Language
also	O
have	O
an	O
implementation	O
in	O
the	O
library	O
heap	B-Application
.	O
</s>
<s>
Python	O
's	O
module	O
implements	O
a	O
binary	B-Application
min-heap	I-Application
on	O
top	O
of	O
a	O
list	O
.	O
</s>
<s>
Java	B-Language
's	O
library	O
contains	O
a	O
class	O
,	O
which	O
implements	O
a	O
min-priority-queue	O
.	O
</s>
<s>
.NET	B-Application
'	O
s	O
library	O
contains	O
a	O
class	O
,	O
which	O
implements	O
an	O
array-backed	O
,	O
quaternary	O
min-heap	B-Application
.	O
</s>
<s>
Scala	B-Application
's	O
library	O
contains	O
a	O
class	O
,	O
which	O
implements	O
a	O
max-priority-queue	O
.	O
</s>
<s>
Go	B-Application
's	O
library	O
contains	O
a	O
module	O
,	O
which	O
implements	O
a	O
min-heap	B-Application
on	O
top	O
of	O
any	O
compatible	O
data	B-General_Concept
structure	I-General_Concept
.	O
</s>
<s>
Apple	O
's	O
Core	B-Operating_System
Foundation	I-Operating_System
framework	O
contains	O
a	O
structure	O
,	O
which	O
implements	O
a	O
min-heap	B-Application
.	O
</s>
<s>
Priority	B-Application
queuing	I-Application
can	O
be	O
used	O
to	O
manage	O
limited	O
resources	O
such	O
as	O
bandwidth	O
on	O
a	O
transmission	O
line	O
from	O
a	O
network	B-Protocol
router	I-Protocol
.	O
</s>
<s>
In	O
the	O
event	O
of	O
outgoing	O
traffic	O
queuing	O
due	O
to	O
insufficient	O
bandwidth	O
,	O
all	O
other	O
queues	B-Application
can	O
be	O
halted	O
to	O
send	O
the	O
traffic	O
from	O
the	O
highest	O
priority	B-Application
queue	I-Application
upon	O
arrival	O
.	O
</s>
<s>
an	O
RTP	B-Protocol
stream	O
of	O
a	O
VoIP	B-Application
connection	O
)	O
is	O
forwarded	O
with	O
the	O
least	O
delay	O
and	O
the	O
least	O
likelihood	O
of	O
being	O
rejected	O
due	O
to	O
a	O
queue	B-Application
reaching	O
its	O
maximum	O
capacity	O
.	O
</s>
<s>
All	O
other	O
traffic	O
can	O
be	O
handled	O
when	O
the	O
highest	O
priority	B-Application
queue	I-Application
is	O
empty	O
.	O
</s>
<s>
Another	O
approach	O
used	O
is	O
to	O
send	O
disproportionately	O
more	O
traffic	O
from	O
higher	O
priority	B-Application
queues	I-Application
.	O
</s>
<s>
Many	O
modern	O
protocols	O
for	O
local	B-General_Concept
area	I-General_Concept
networks	I-General_Concept
also	O
include	O
the	O
concept	O
of	O
priority	B-Application
queues	I-Application
at	O
the	O
media	B-Protocol
access	I-Protocol
control	I-Protocol
(	O
MAC	O
)	O
sub-layer	O
to	O
ensure	O
that	O
high-priority	O
applications	O
(	O
such	O
as	O
VoIP	B-Application
or	O
IPTV	O
)	O
experience	O
lower	O
latency	O
than	O
other	O
applications	O
which	O
can	O
be	O
served	O
with	O
best-effort	O
service	O
.	O
</s>
<s>
Examples	O
include	O
IEEE	O
802.11e	O
(	O
an	O
amendment	O
to	O
IEEE	O
802.11	O
which	O
provides	O
quality	O
of	O
service	O
)	O
and	O
ITU-T	B-General_Concept
G.hn	I-General_Concept
(	O
a	O
standard	O
for	O
high-speed	O
local	B-General_Concept
area	I-General_Concept
network	I-General_Concept
using	O
existing	O
home	O
wiring	O
(	O
power	B-Device
lines	I-Device
,	O
phone	O
lines	O
and	O
coaxial	B-Protocol
cables	I-Protocol
)	O
.	O
</s>
<s>
Usually	O
a	O
limitation	O
(	O
policer	O
)	O
is	O
set	O
to	O
limit	O
the	O
bandwidth	O
that	O
traffic	O
from	O
the	O
highest	O
priority	B-Application
queue	I-Application
can	O
take	O
,	O
in	O
order	O
to	O
prevent	O
high	O
priority	O
packets	O
from	O
choking	O
off	O
all	O
other	O
traffic	O
.	O
</s>
<s>
Another	O
use	O
of	O
a	O
priority	B-Application
queue	I-Application
is	O
to	O
manage	O
the	O
events	O
in	O
a	O
discrete	B-General_Concept
event	I-General_Concept
simulation	I-General_Concept
.	O
</s>
<s>
The	O
events	O
are	O
added	O
to	O
the	O
queue	B-Application
with	O
their	O
simulation	O
time	O
used	O
as	O
the	O
priority	O
.	O
</s>
<s>
The	O
execution	O
of	O
the	O
simulation	O
proceeds	O
by	O
repeatedly	O
pulling	O
the	O
top	O
of	O
the	O
queue	B-Application
and	O
executing	O
the	O
event	O
thereon	O
.	O
</s>
<s>
When	O
the	O
graph	O
is	O
stored	O
in	O
the	O
form	O
of	O
adjacency	B-Data_Structure
list	I-Data_Structure
or	O
matrix	O
,	O
priority	B-Application
queue	I-Application
can	O
be	O
used	O
to	O
extract	O
minimum	O
efficiently	O
when	O
implementing	O
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
,	O
although	O
one	O
also	O
needs	O
the	O
ability	O
to	O
alter	O
the	O
priority	O
of	O
a	O
particular	O
vertex	O
in	O
the	O
priority	B-Application
queue	I-Application
efficiently	O
.	O
</s>
<s>
If	O
instead	O
,	O
a	O
graph	O
is	O
stored	O
as	O
node	O
objects	O
,	O
and	O
priority-node	O
pairs	O
are	O
inserted	O
into	O
a	O
heap	B-Application
,	O
altering	O
the	O
priority	O
of	O
a	O
particular	O
vertex	O
is	O
not	O
necessary	O
if	O
one	O
tracks	O
visited	O
nodes	O
.	O
</s>
<s>
Once	O
a	O
node	O
is	O
visited	O
,	O
if	O
it	O
comes	O
up	O
in	O
the	O
heap	B-Application
again	O
(	O
having	O
had	O
a	O
lower	O
priority	O
number	O
associated	O
with	O
it	O
earlier	O
)	O
,	O
it	O
is	O
popped-off	O
and	O
ignored	O
.	O
</s>
<s>
Huffman	B-General_Concept
coding	I-General_Concept
requires	O
one	O
to	O
repeatedly	O
obtain	O
the	O
two	O
lowest-frequency	O
trees	O
.	O
</s>
<s>
A	O
priority	B-Application
queue	I-Application
is	O
one	O
method	O
of	O
doing	O
this	O
.	O
</s>
<s>
Best-first	B-Algorithm
search	I-Algorithm
algorithms	O
,	O
like	O
the	O
A*	B-Protocol
search	I-Protocol
algorithm	I-Protocol
,	O
find	O
the	O
shortest	O
path	O
between	O
two	O
vertices	O
or	O
nodes	O
of	O
a	O
weighted	O
graph	O
,	O
trying	O
out	O
the	O
most	O
promising	O
routes	O
first	O
.	O
</s>
<s>
A	O
priority	B-Application
queue	I-Application
(	O
also	O
known	O
as	O
the	O
fringe	O
)	O
is	O
used	O
to	O
keep	O
track	O
of	O
unexplored	O
routes	O
;	O
the	O
one	O
for	O
which	O
the	O
estimate	O
(	O
a	O
lower	O
bound	O
in	O
the	O
case	O
of	O
A*	O
)	O
of	O
the	O
total	O
path	O
length	O
is	O
smallest	O
is	O
given	O
highest	O
priority	O
.	O
</s>
<s>
If	O
memory	O
limitations	O
make	O
best-first	B-Algorithm
search	I-Algorithm
impractical	O
,	O
variants	O
like	O
the	O
SMA*	B-Protocol
algorithm	O
can	O
be	O
used	O
instead	O
,	O
with	O
a	O
double-ended	B-Application
priority	I-Application
queue	I-Application
to	O
allow	O
removal	O
of	O
low-priority	O
items	O
.	O
</s>
<s>
The	O
Real-time	O
Optimally	O
Adapting	O
Meshes	O
(	O
ROAM	B-Algorithm
)	O
algorithm	O
computes	O
a	O
dynamically	O
changing	O
triangulation	O
of	O
a	O
terrain	O
.	O
</s>
<s>
The	O
algorithm	O
uses	O
two	O
priority	B-Application
queues	I-Application
,	O
one	O
for	O
triangles	O
that	O
can	O
be	O
split	O
and	O
another	O
for	O
triangles	O
that	O
can	O
be	O
merged	O
.	O
</s>
<s>
In	O
each	O
step	O
the	O
triangle	O
from	O
the	O
split	O
queue	B-Application
with	O
the	O
highest	O
priority	O
is	O
split	O
,	O
or	O
the	O
triangle	O
from	O
the	O
merge	O
queue	B-Application
with	O
the	O
lowest	O
priority	O
is	O
merged	O
with	O
its	O
neighbours	O
.	O
</s>
<s>
Using	O
min	B-Application
heap	I-Application
priority	I-Application
queue	I-Application
in	O
Prim	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
to	O
find	O
the	O
minimum	O
spanning	O
tree	O
of	O
a	O
connected	O
and	O
undirected	O
graph	O
,	O
one	O
can	O
achieve	O
a	O
good	O
running	O
time	O
.	O
</s>
<s>
This	O
min	B-Application
heap	I-Application
priority	I-Application
queue	I-Application
uses	O
the	O
min	B-Application
heap	I-Application
data	B-General_Concept
structure	I-General_Concept
which	O
supports	O
operations	O
such	O
as	O
insert	O
,	O
minimum	O
,	O
extract-min	O
,	O
decrease-key	O
.	O
</s>
<s>
Parallelization	O
can	O
be	O
used	O
to	O
speed	O
up	O
priority	B-Application
queues	I-Application
,	O
but	O
requires	O
some	O
changes	O
to	O
the	O
priority	B-Application
queue	I-Application
interface	O
.	O
</s>
<s>
One	O
possible	O
change	O
is	O
to	O
allow	O
the	O
concurrent	O
access	O
of	O
multiple	O
processors	O
to	O
the	O
same	O
priority	B-Application
queue	I-Application
.	O
</s>
<s>
If	O
the	O
priority	B-Application
queue	I-Application
allows	O
concurrent	O
access	O
,	O
multiple	O
processes	O
can	O
perform	O
operations	O
concurrently	O
on	O
that	O
priority	B-Application
queue	I-Application
.	O
</s>
<s>
This	O
restricts	O
parallelism	O
on	O
the	O
level	O
of	O
the	O
program	O
using	O
the	O
priority	B-Application
queue	I-Application
.	O
</s>
<s>
The	O
concurrent	O
access	O
to	O
a	O
priority	B-Application
queue	I-Application
can	O
be	O
implemented	O
on	O
a	O
Concurrent	O
Read	O
,	O
Concurrent	O
Write	O
(	O
CRCW	O
)	O
PRAM	O
model	O
.	O
</s>
<s>
In	O
the	O
following	O
the	O
priority	B-Application
queue	I-Application
is	O
implemented	O
as	O
a	O
skip	O
list	O
.	O
</s>
<s>
In	O
addition	O
,	O
an	O
atomic	O
synchronization	O
primitive	O
,	O
CAS	B-Operating_System
,	O
is	O
used	O
to	O
make	O
the	O
skip	O
list	O
lock-free	O
.	O
</s>
<s>
The	O
nodes	O
of	O
the	O
skip	O
list	O
consists	O
of	O
a	O
unique	O
key	O
,	O
a	O
priority	O
,	O
an	O
array	B-Data_Structure
of	O
pointers	O
,	O
for	O
each	O
level	O
,	O
to	O
the	O
next	O
nodes	O
and	O
a	O
delete	O
mark	O
.	O
</s>
<s>
In	O
addition	O
,	O
the	O
node	O
is	O
assigned	O
a	O
number	O
of	O
levels	O
,	O
which	O
dictates	O
the	O
size	O
of	O
the	O
array	B-Data_Structure
of	O
pointers	O
.	O
</s>
<s>
If	O
the	O
concurrent	O
access	O
to	O
a	O
priority	B-Application
queue	I-Application
is	O
allowed	O
,	O
conflicts	O
may	O
arise	O
between	O
two	O
processes	O
.	O
</s>
<s>
In	O
this	O
setting	O
,	O
operations	O
on	O
a	O
priority	B-Application
queue	I-Application
is	O
generalized	O
to	O
a	O
batch	O
of	O
elements	O
.	O
</s>
<s>
For	O
instance	O
,	O
k_extract-min	O
deletes	O
the	O
smallest	O
elements	O
of	O
the	O
priority	B-Application
queue	I-Application
and	O
returns	O
those	O
.	O
</s>
<s>
In	O
a	O
shared-memory	B-Application
setting	I-Application
,	O
the	O
parallel	O
priority	B-Application
queue	I-Application
can	O
be	O
easily	O
implemented	O
using	O
parallel	O
binary	B-Language
search	I-Language
trees	I-Language
and	O
join-based	O
tree	O
algorithms	O
.	O
</s>
<s>
In	O
particular	O
,	O
k_extract-min	O
corresponds	O
to	O
a	O
split	O
on	O
the	O
binary	B-Language
search	I-Language
tree	I-Language
that	O
has	O
cost	O
and	O
yields	O
a	O
tree	O
that	O
contains	O
the	O
smallest	O
elements	O
.	O
</s>
<s>
k_insert	O
can	O
be	O
applied	O
by	O
a	O
union	O
of	O
the	O
original	O
priority	B-Application
queue	I-Application
and	O
the	O
batch	O
of	O
insertions	O
.	O
</s>
<s>
Other	O
operations	O
for	O
priority	B-Application
queue	I-Application
can	O
be	O
applied	O
similarly	O
.	O
</s>
<s>
The	O
rest	O
of	O
this	O
section	O
discusses	O
a	O
queue-based	O
algorithm	O
on	O
distributed	O
memory	O
.	O
</s>
<s>
We	O
assume	O
each	O
processor	O
has	O
its	O
own	O
local	O
memory	O
and	O
a	O
local	O
(	O
sequential	O
)	O
priority	B-Application
queue	I-Application
.	O
</s>
<s>
The	O
elements	O
of	O
the	O
global	O
(	O
parallel	O
)	O
priority	B-Application
queue	I-Application
are	O
distributed	O
across	O
all	O
processors	O
.	O
</s>
<s>
A	O
k_insert	O
operation	O
assigns	O
the	O
elements	O
uniformly	O
random	O
to	O
the	O
processors	O
which	O
insert	O
the	O
elements	O
into	O
their	O
local	O
queues	B-Application
.	O
</s>
<s>
Note	O
that	O
single	O
elements	O
can	O
still	O
be	O
inserted	O
into	O
the	O
queue	B-Application
.	O
</s>
<s>
Thus	O
each	O
processor	O
holds	O
a	O
representative	O
part	O
of	O
the	O
global	O
priority	B-Application
queue	I-Application
.	O
</s>
<s>
This	O
property	O
is	O
used	O
when	O
k_extract-min	O
is	O
executed	O
,	O
as	O
the	O
smallest	O
elements	O
of	O
each	O
local	O
queue	B-Application
are	O
removed	O
and	O
collected	O
in	O
a	O
result	O
set	O
.	O
</s>
<s>
The	O
number	O
of	O
elements	O
that	O
is	O
removed	O
from	O
each	O
local	O
queue	B-Application
depends	O
on	O
and	O
the	O
number	O
of	O
processors	O
.	O
</s>
<s>
If	O
not	O
,	O
elements	O
are	O
again	O
removed	O
from	O
each	O
local	O
queue	B-Application
and	O
put	O
into	O
the	O
result	O
set	O
.	O
</s>
<s>
All	O
other	O
elements	O
of	O
the	O
result	O
set	O
are	O
inserted	O
back	O
into	O
their	O
local	O
queues	B-Application
.	O
</s>
<s>
The	O
running	O
time	O
of	O
k_extract-min	O
is	O
expected	O
,	O
where	O
and	O
is	O
the	O
size	O
of	O
the	O
priority	B-Application
queue	I-Application
.	O
</s>
<s>
The	O
priority	B-Application
queue	I-Application
can	O
be	O
further	O
improved	O
by	O
not	O
moving	O
the	O
remaining	O
elements	O
of	O
the	O
result	O
set	O
directly	O
back	O
into	O
the	O
local	O
queues	B-Application
after	O
a	O
k_extract-min	O
operation	O
.	O
</s>
<s>
This	O
saves	O
moving	O
elements	O
back	O
and	O
forth	O
all	O
the	O
time	O
between	O
the	O
result	O
set	O
and	O
the	O
local	O
queues	B-Application
.	O
</s>
<s>
But	O
not	O
all	O
algorithms	O
can	O
use	O
this	O
kind	O
of	O
priority	B-Application
queue	I-Application
.	O
</s>
<s>
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
for	O
example	O
can	O
not	O
work	O
on	O
several	O
nodes	O
at	O
once	O
.	O
</s>
<s>
The	O
algorithm	O
takes	O
the	O
node	O
with	O
the	O
smallest	O
distance	O
from	O
the	O
priority	B-Application
queue	I-Application
and	O
calculates	O
new	O
distances	O
for	O
all	O
its	O
neighbor	O
nodes	O
.	O
</s>
<s>
So	O
using	O
k-element	O
operations	O
destroys	O
the	O
label	O
setting	O
property	O
of	O
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
.	O
</s>
