<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
a	O
min-max	B-Application
heap	I-Application
is	O
a	O
complete	O
binary	O
tree	O
data	B-General_Concept
structure	I-General_Concept
which	O
combines	O
the	O
usefulness	O
of	O
both	O
a	O
min-heap	B-Application
and	O
a	O
max-heap	B-Application
,	O
that	O
is	O
,	O
it	O
provides	O
constant	O
time	O
retrieval	O
and	O
logarithmic	O
time	O
removal	O
of	O
both	O
the	O
minimum	O
and	O
maximum	O
elements	O
in	O
it	O
.	O
</s>
<s>
This	O
makes	O
the	O
min-max	B-Application
heap	I-Application
a	O
very	O
useful	O
data	B-General_Concept
structure	I-General_Concept
to	O
implement	O
a	O
double-ended	B-Application
priority	I-Application
queue	I-Application
.	O
</s>
<s>
Like	O
binary	O
min-heaps	B-Application
and	O
max-heaps	B-Application
,	O
min-max	B-Application
heaps	I-Application
support	O
logarithmic	O
insertion	O
and	O
deletion	O
and	O
can	O
be	O
built	O
in	O
linear	O
time	O
.	O
</s>
<s>
Min-max	B-Application
heaps	I-Application
are	O
often	O
represented	O
implicitly	O
in	O
an	O
array	O
;	O
hence	O
it	O
's	O
referred	O
to	O
as	O
an	O
implicit	B-Data_Structure
data	I-Data_Structure
structure	I-Data_Structure
.	O
</s>
<s>
The	O
min-max	B-Application
heap	I-Application
property	O
is	O
:	O
each	O
node	O
at	O
an	O
even	O
level	O
in	O
the	O
tree	O
is	O
less	O
than	O
all	O
of	O
its	O
descendants	O
,	O
while	O
each	O
node	O
at	O
an	O
odd	O
level	O
in	O
the	O
tree	O
is	O
greater	O
than	O
all	O
of	O
its	O
descendants	O
.	O
</s>
<s>
The	O
notion	O
of	O
min-max	O
ordering	O
can	O
be	O
extended	O
to	O
other	O
structures	O
based	O
on	O
the	O
max	O
-	O
or	O
min-ordering	O
,	O
such	O
as	O
leftist	B-Application
trees	I-Application
,	O
generating	O
a	O
new	O
(	O
and	O
more	O
powerful	O
)	O
class	O
of	O
data	B-General_Concept
structures	I-General_Concept
.	O
</s>
<s>
A	O
min-max	B-Application
heap	I-Application
can	O
also	O
be	O
useful	O
when	O
implementing	O
an	O
external	O
quicksort	O
.	O
</s>
<s>
A	O
min-max	B-Application
heap	I-Application
is	O
a	O
complete	O
binary	O
tree	O
containing	O
alternating	O
min	O
(	O
or	O
even	O
)	O
and	O
max	O
(	O
or	O
odd	O
)	O
levels	O
.	O
</s>
<s>
Each	O
node	O
in	O
a	O
min-max	B-Application
heap	I-Application
has	O
a	O
data	O
member	O
(	O
usually	O
called	O
key	O
)	O
whose	O
value	O
is	O
used	O
to	O
determine	O
the	O
order	O
of	O
the	O
node	O
in	O
the	O
min-max	B-Application
heap	I-Application
.	O
</s>
<s>
The	O
root	O
element	O
is	O
the	O
smallest	O
element	O
in	O
the	O
min-max	B-Application
heap	I-Application
.	O
</s>
<s>
Let	O
be	O
any	O
node	O
in	O
a	O
min-max	B-Application
heap	I-Application
.	O
</s>
<s>
A	O
max-min	O
heap	B-Application
is	O
defined	O
analogously	O
;	O
in	O
such	O
a	O
heap	B-Application
,	O
the	O
maximum	O
value	O
is	O
stored	O
at	O
the	O
root	O
,	O
and	O
the	O
smallest	O
value	O
is	O
stored	O
at	O
one	O
of	O
the	O
root	O
's	O
children	O
.	O
</s>
<s>
In	O
the	O
following	O
operations	O
we	O
assume	O
that	O
the	O
min-max	B-Application
heap	I-Application
is	O
represented	O
in	O
an	O
array	O
1	O
..	O
N	O
The	O
location	O
in	O
the	O
array	O
will	O
correspond	O
to	O
a	O
node	O
located	O
on	O
the	O
level	O
in	O
the	O
heap	B-Application
.	O
</s>
<s>
Creating	O
a	O
min-max	B-Application
heap	I-Application
is	O
accomplished	O
by	O
an	O
adaptation	O
of	O
Floyd	O
's	O
linear-time	O
heap	B-Application
construction	O
algorithm	O
,	O
which	O
proceeds	O
in	O
a	O
bottom-up	O
fashion	O
.	O
</s>
<s>
A	O
typical	O
Floyd	O
's	O
build-heap	O
algorithm	O
goes	O
as	O
follows	O
:	O
</s>
<s>
function	O
FLOYD-BUILD-HEAP(h )	O
:	O
</s>
<s>
In	O
this	O
function	O
,	O
h	O
is	O
the	O
initial	O
array	O
,	O
whose	O
elements	O
may	O
not	O
be	O
ordered	O
according	O
to	O
the	O
min-max	B-Application
heap	I-Application
property	O
.	O
</s>
<s>
The	O
push-down	O
operation	O
(	O
which	O
sometimes	O
is	O
also	O
called	O
heapify	B-Application
)	O
of	O
a	O
min-max	B-Application
heap	I-Application
is	O
explained	O
next	O
.	O
</s>
<s>
To	O
add	O
an	O
element	O
to	O
a	O
min-max	B-Application
heap	I-Application
perform	O
following	O
operations	O
:	O
</s>
<s>
Append	O
the	O
required	O
key	O
to	O
(	O
the	O
end	O
of	O
)	O
the	O
array	O
representing	O
the	O
min-max	B-Application
heap	I-Application
.	O
</s>
<s>
This	O
will	O
likely	O
break	O
the	O
min-max	B-Application
heap	I-Application
properties	O
,	O
therefore	O
we	O
need	O
to	O
adjust	O
the	O
heap	B-Application
.	O
</s>
<s>
If	O
it	O
is	O
found	O
to	O
be	O
less	O
(	O
greater	O
)	O
than	O
the	O
parent	O
,	O
then	O
it	O
is	O
surely	O
less	O
(	O
greater	O
)	O
than	O
all	O
other	O
nodes	O
on	O
max	O
(	O
min	O
)	O
levels	O
that	O
are	O
on	O
the	O
path	O
to	O
the	O
root	O
of	O
heap	B-Application
.	O
</s>
<s>
Here	O
is	O
one	O
example	O
for	O
inserting	O
an	O
element	O
to	O
a	O
Min-Max	B-Application
Heap	I-Application
.	O
</s>
<s>
Say	O
we	O
have	O
the	O
following	O
min-max	B-Application
heap	I-Application
and	O
want	O
to	O
insert	O
a	O
new	O
node	O
with	O
value	O
6	O
.	O
</s>
<s>
So	O
,	O
6	O
gets	O
moved	O
to	O
the	O
root	O
position	O
of	O
the	O
heap	B-Application
,	O
the	O
former	O
root	O
8	O
gets	O
moved	O
down	O
to	O
replace	O
11	O
,	O
and	O
11	O
becomes	O
a	O
right	O
child	O
of	O
8	O
.	O
</s>
<s>
The	O
minimum	O
node	O
(	O
or	O
a	O
minimum	O
node	O
in	O
the	O
case	O
of	O
duplicate	O
keys	O
)	O
of	O
a	O
Min-Max	B-Application
Heap	I-Application
is	O
always	O
located	O
at	O
the	O
root	O
.	O
</s>
<s>
The	O
maximum	O
node	O
(	O
or	O
a	O
maximum	O
node	O
in	O
the	O
case	O
of	O
duplicate	O
keys	O
)	O
of	O
a	O
Min-Max	B-Application
Heap	I-Application
that	O
contains	O
more	O
than	O
one	O
node	O
is	O
always	O
located	O
on	O
the	O
first	O
max	O
level--i.e.	O
,	O
as	O
one	O
of	O
the	O
immediate	O
children	O
of	O
the	O
root	O
.	O
</s>
<s>
If	O
the	O
Min-Max	B-Application
heap	I-Application
containd	O
one	O
node	O
then	O
that	O
node	O
is	O
the	O
maximum	O
node	O
.	O
</s>
<s>
push-down	O
is	O
then	O
called	O
on	O
the	O
root	O
index	O
to	O
restore	O
the	O
heap	B-Application
property	I-Application
in	O
time	O
.	O
</s>
<s>
As	O
in	O
the	O
Find	O
Maximum	O
operation	O
,	O
a	O
single	O
comparison	O
is	O
required	O
to	O
identify	O
the	O
maximal	O
child	O
of	O
the	O
root	O
,	O
after	O
which	O
it	O
is	O
replaced	O
with	O
the	O
final	O
element	O
of	O
the	O
array	O
and	O
push-down	O
is	O
then	O
called	O
on	O
the	O
index	O
of	O
the	O
replaced	O
maximum	O
to	O
restore	O
the	O
heap	B-Application
property	I-Application
.	O
</s>
<s>
The	O
min-max-median	O
heap	B-Application
is	O
a	O
variant	O
of	O
the	O
min-max	B-Application
heap	I-Application
,	O
suggested	O
in	O
the	O
original	O
publication	O
on	O
the	O
structure	O
,	O
that	O
supports	O
the	O
operations	O
of	O
an	O
order	B-Algorithm
statistic	I-Algorithm
tree	I-Algorithm
.	O
</s>
