<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
a	O
queap	B-Application
is	O
a	O
priority	B-Application
queue	I-Application
data	B-General_Concept
structure	I-General_Concept
.	O
</s>
<s>
The	O
data	B-General_Concept
structure	I-General_Concept
allows	O
insertions	O
and	O
deletions	O
of	O
arbitrary	O
elements	O
,	O
as	O
well	O
as	O
retrieval	O
of	O
the	O
highest-priority	O
element	O
.	O
</s>
<s>
Each	O
deletion	O
takes	O
amortized	B-General_Concept
time	I-General_Concept
logarithmic	O
in	O
the	O
number	O
of	O
items	O
that	O
have	O
been	O
in	O
the	O
structure	O
for	O
a	O
longer	O
time	O
than	O
the	O
removed	O
item	O
.	O
</s>
<s>
Insertions	O
take	O
constant	O
amortized	B-General_Concept
time	I-General_Concept
.	O
</s>
<s>
The	O
data	B-General_Concept
structure	I-General_Concept
consists	O
of	O
a	O
doubly	B-Data_Structure
linked	I-Data_Structure
list	I-Data_Structure
and	O
a	O
2	B-Data_Structure
–	I-Data_Structure
4	I-Data_Structure
tree	I-Data_Structure
data	B-General_Concept
structure	I-General_Concept
,	O
each	O
modified	O
to	O
keep	O
track	O
of	O
its	O
minimum-priority	O
element	O
.	O
</s>
<s>
The	O
basic	O
operation	O
of	O
the	O
structure	O
is	O
to	O
keep	O
newly	O
inserted	O
elements	O
in	O
the	O
doubly	B-Data_Structure
linked	I-Data_Structure
list	I-Data_Structure
,	O
until	O
a	O
deletion	O
would	O
remove	O
one	O
of	O
the	O
list	O
items	O
,	O
at	O
which	O
point	O
they	O
are	O
all	O
moved	O
into	O
the	O
2	B-Data_Structure
–	I-Data_Structure
4	I-Data_Structure
tree	I-Data_Structure
.	O
</s>
<s>
The	O
2	B-Data_Structure
–	I-Data_Structure
4	I-Data_Structure
tree	I-Data_Structure
stores	O
its	O
elements	O
in	O
insertion	O
order	O
,	O
rather	O
than	O
the	O
more	O
conventional	O
priority-sorted	O
order	O
.	O
</s>
<s>
Both	O
the	O
data	B-General_Concept
structure	I-General_Concept
and	O
its	O
name	O
were	O
devised	O
by	O
John	O
Iacono	O
and	O
Stefan	O
Langerman	O
.	O
</s>
<s>
A	O
queap	B-Application
is	O
a	O
priority	B-Application
queue	I-Application
that	O
inserts	O
elements	O
in	O
O(1 )	O
amortized	B-General_Concept
time	I-General_Concept
,	O
and	O
removes	O
the	O
minimum	O
element	O
in	O
O( log( k+2	O
)	O
)	O
if	O
there	O
are	O
k	O
items	O
that	O
have	O
been	O
in	O
the	O
heap	O
for	O
a	O
longer	O
time	O
than	O
the	O
element	O
to	O
be	O
extracted	O
.	O
</s>
<s>
The	O
queap	B-Application
has	O
a	O
property	O
called	O
the	O
queueish	O
property	O
:	O
the	O
time	O
to	O
search	O
for	O
element	O
x	O
is	O
O( lg	O
q(x )	O
)	O
where	O
q(x )	O
is	O
equal	O
to	O
n1w(x )	O
and	O
w(x )	O
is	O
the	O
number	O
of	O
distinct	O
items	O
that	O
has	O
been	O
accessed	O
by	O
operations	O
such	O
as	O
searching	O
,	O
inserting	O
,	O
or	O
deleting	O
.	O
</s>
<s>
Indeed	O
,	O
the	O
queueish	O
property	O
is	O
the	O
complement	O
of	O
the	O
splay	B-Data_Structure
tree	I-Data_Structure
working	O
set	O
property	O
:	O
the	O
time	O
to	O
search	O
for	O
element	O
x	O
is	O
O( lg	O
w(x )	O
)	O
.	O
</s>
<s>
A	O
queap	B-Application
can	O
be	O
represented	O
by	O
two	O
data	B-General_Concept
structures	I-General_Concept
:	O
a	O
doubly	B-Data_Structure
linked	I-Data_Structure
list	I-Data_Structure
and	O
a	O
modified	O
version	O
of	O
2	B-Data_Structure
–	I-Data_Structure
4	I-Data_Structure
tree	I-Data_Structure
.	O
</s>
<s>
The	O
doubly	B-Data_Structure
linked	I-Data_Structure
list	I-Data_Structure
,	O
L	O
,	O
is	O
used	O
for	O
a	O
series	O
of	O
insert	O
and	O
locate-min	O
operations	O
.	O
</s>
<s>
The	O
queap	B-Application
keeps	O
a	O
pointer	O
to	O
the	O
minimum	O
element	O
stored	O
in	O
the	O
list	O
.	O
</s>
<s>
This	O
operation	O
is	O
done	O
to	O
determine	O
if	O
the	O
element	O
is	O
either	O
in	O
the	O
list	O
or	O
in	O
a	O
2	B-Data_Structure
–	I-Data_Structure
4	I-Data_Structure
tree	I-Data_Structure
.	O
</s>
<s>
A	O
2	B-Data_Structure
–	I-Data_Structure
4	I-Data_Structure
tree	I-Data_Structure
is	O
used	O
when	O
a	O
delete	O
operation	O
occurs	O
.	O
</s>
<s>
If	O
the	O
item	O
x	O
is	O
already	O
in	O
tree	O
T	O
,	O
the	O
item	O
is	O
removed	O
using	O
the	O
2	B-Data_Structure
–	I-Data_Structure
4	I-Data_Structure
tree	I-Data_Structure
delete	O
operation	O
.	O
</s>
<s>
All	O
the	O
elements	O
stored	O
in	O
list	O
L	O
are	O
then	O
added	O
to	O
the	O
2	B-Data_Structure
–	I-Data_Structure
4	I-Data_Structure
tree	I-Data_Structure
,	O
setting	O
the	O
bit	O
variable	O
of	O
each	O
element	O
to	O
zero	O
.	O
</s>
<s>
A	O
queap	B-Application
uses	O
only	O
the	O
2	B-Data_Structure
–	I-Data_Structure
4	I-Data_Structure
tree	I-Data_Structure
structure	O
properties	O
,	O
not	O
a	O
search	O
tree	O
.	O
</s>
<s>
The	O
modified	O
2	B-Data_Structure
–	I-Data_Structure
4	I-Data_Structure
tree	I-Data_Structure
structure	O
is	O
as	O
follows	O
.	O
</s>
<s>
When	O
the	O
deletion	O
operation	O
is	O
invoked	O
,	O
the	O
set	O
of	O
elements	O
stored	O
in	O
L	O
is	O
then	O
added	O
to	O
the	O
leaves	O
of	O
the	O
2	B-Data_Structure
–	I-Data_Structure
4	I-Data_Structure
tree	I-Data_Structure
in	O
that	O
order	O
,	O
proceeded	O
by	O
a	O
dummy	O
leaf	O
containing	O
an	O
infinite	O
key	O
.	O
</s>
<s>
The	O
queap	B-Application
has	O
a	O
pointer	O
to	O
,	O
which	O
points	O
to	O
the	O
smallest	O
element	O
in	O
T	O
.	O
</s>
<s>
An	O
application	O
of	O
queaps	B-Application
includes	O
a	O
unique	O
set	O
of	O
high	O
priority	O
events	O
and	O
extraction	O
of	O
the	O
highest	O
priority	O
event	O
for	O
processing	O
.	O
</s>
<s>
Let	O
minL	O
be	O
a	O
pointer	O
that	O
points	O
to	O
the	O
minimum	O
element	O
in	O
the	O
doubly	B-Data_Structure
linked	I-Data_Structure
list	I-Data_Structure
L	O
,	O
be	O
the	O
minimum	O
element	O
stored	O
in	O
the	O
2	B-Data_Structure
–	I-Data_Structure
4	I-Data_Structure
tree	I-Data_Structure
,	O
T	O
,	O
k	O
be	O
the	O
number	O
of	O
elements	O
stored	O
in	O
T	O
,	O
and	O
n	O
be	O
the	O
total	O
number	O
of	O
elements	O
stored	O
in	O
queap	B-Application
Q	O
.	O
</s>
<s>
New(Q )	O
:	O
Initializes	O
a	O
new	O
empty	O
queap	B-Application
.	O
</s>
<s>
Initialize	O
an	O
empty	O
doubly	B-Data_Structure
linked	I-Data_Structure
list	I-Data_Structure
L	O
and	O
2	B-Data_Structure
–	I-Data_Structure
4	I-Data_Structure
tree	I-Data_Structure
T	O
.	O
Set	O
k	O
and	O
n	O
to	O
zero	O
.	O
</s>
<s>
Insert(Q, x )	O
:	O
Add	O
the	O
element	O
x	O
to	O
queap	B-Application
Q	O
.	O
</s>
<s>
Minimum(Q )	O
:	O
Retrieve	O
a	O
pointer	O
to	O
the	O
smallest	O
element	O
from	O
queap	B-Application
Q	O
.	O
</s>
<s>
Delete(Q, x )	O
:	O
Remove	O
element	O
x	O
from	O
queap	B-Application
Q	O
.	O
</s>
<s>
Each	O
element	O
is	O
added	O
to	O
the	O
parent	O
of	O
the	O
right	O
most	O
child	O
of	O
T	O
using	O
the	O
insert	O
operation	O
of	O
the	O
2	B-Data_Structure
–	I-Data_Structure
4	I-Data_Structure
tree	I-Data_Structure
.	O
</s>
<s>
If	O
the	O
bit	O
of	O
the	O
element	O
x	O
is	O
set	O
to	O
zero	O
,	O
x	O
is	O
a	O
leaf	O
of	O
T	O
.	O
Delete	O
x	O
using	O
the	O
2	B-Data_Structure
–	I-Data_Structure
4	I-Data_Structure
tree	I-Data_Structure
delete	O
operation	O
.	O
</s>
<s>
DeleteMin(Q )	O
:	O
Delete	O
and	O
return	O
the	O
smallest	O
element	O
from	O
queap	B-Application
Q	O
.	O
</s>
<s>
Starting	O
from	O
the	O
root	O
of	O
the	O
tree	O
T	O
,	O
traverse	O
the	O
tree	O
using	O
the	O
post-order	B-Algorithm
traversal	I-Algorithm
algorithm	O
,	O
deleting	O
each	O
node	O
in	O
the	O
tree	O
.	O
</s>
<s>
The	O
running	O
time	O
is	O
analyzed	O
using	O
the	O
amortized	B-General_Concept
analysis	I-General_Concept
.	O
</s>
<s>
The	O
potential	O
function	O
for	O
queap	B-Application
Q	O
will	O
be	O
where	O
.	O
</s>
<s>
Minimum(Q )	O
:	O
The	O
operation	O
does	O
not	O
alter	O
the	O
data	B-General_Concept
structure	I-General_Concept
so	O
the	O
amortized	B-General_Concept
cost	O
is	O
equal	O
to	O
its	O
actual	O
cost	O
,	O
O(1 )	O
.	O
</s>
<s>
If	O
x	O
is	O
in	O
tree	O
T	O
,	O
then	O
the	O
amortized	B-General_Concept
cost	O
is	O
not	O
modified	O
.	O
</s>
<s>
The	O
delete	O
operation	O
is	O
O(1 )	O
amortized	B-General_Concept
2	B-Data_Structure
–	I-Data_Structure
4	I-Data_Structure
tree	I-Data_Structure
.	O
</s>
<s>
If	O
x	O
is	O
in	O
list	O
L	O
,	O
then	O
all	O
the	O
elements	O
from	O
L	O
are	O
inserted	O
in	O
T	O
.	O
This	O
has	O
a	O
cost	O
of	O
of	O
some	O
constant	O
a	O
,	O
amortized	B-General_Concept
over	O
the	O
2	B-Data_Structure
–	I-Data_Structure
4	I-Data_Structure
tree	I-Data_Structure
.	O
</s>
<s>
If	O
,	O
then	O
the	O
amortized	B-General_Concept
cost	O
will	O
be	O
.	O
</s>
<s>
Delete(Q, x )	O
:	O
is	O
the	O
addition	O
of	O
the	O
amortized	B-General_Concept
cost	O
of	O
Minimum(Q )	O
and	O
Delete(Q, x )	O
,	O
which	O
is	O
.	O
</s>
<s>
A	O
small	O
Java	B-Language
implementation	O
of	O
a	O
queap	B-Application
:	O
</s>
