<s>
Tournament	B-Algorithm
sort	I-Algorithm
is	O
a	O
sorting	B-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
It	O
improves	O
upon	O
the	O
naive	O
selection	B-Algorithm
sort	I-Algorithm
by	O
using	O
a	O
priority	B-Application
queue	I-Application
to	O
find	O
the	O
next	O
element	O
in	O
the	O
sort	O
.	O
</s>
<s>
In	O
the	O
naive	O
selection	B-Algorithm
sort	I-Algorithm
,	O
it	O
takes	O
O(n )	O
operations	O
to	O
select	O
the	O
next	O
element	O
of	O
n	O
elements	O
;	O
in	O
a	O
tournament	B-Algorithm
sort	I-Algorithm
,	O
it	O
takes	O
O(logn )	O
operations	O
(	O
after	O
building	O
the	O
initial	O
tournament	O
in	O
O(n )	O
)	O
.	O
</s>
<s>
Tournament	B-Algorithm
sort	I-Algorithm
is	O
a	O
variation	O
of	O
heapsort	B-Application
.	O
</s>
<s>
Tournament	O
replacement	O
selection	B-Algorithm
sorts	I-Algorithm
are	O
used	O
to	O
gather	O
the	O
initial	O
runs	O
for	O
external	O
sorting	B-Algorithm
algorithms	I-Algorithm
.	O
</s>
<s>
Conceptually	O
,	O
an	O
external	O
file	O
is	O
read	O
and	O
its	O
elements	O
are	O
pushed	O
into	O
the	O
priority	B-Application
queue	I-Application
until	O
the	O
queue	O
is	O
full	O
.	O
</s>
<s>
On	O
average	O
,	O
a	O
run	O
will	O
be	O
100%	O
longer	O
than	O
the	O
capacity	O
of	O
the	O
priority	B-Application
queue	I-Application
.	O
</s>
<s>
Tournament	B-Algorithm
sorts	I-Algorithm
may	O
also	O
be	O
used	O
in	O
N-way	O
merges	O
.	O
</s>
<s>
The	O
following	O
is	O
an	O
implementation	O
of	O
tournament	B-Algorithm
sort	I-Algorithm
in	O
Haskell	B-Language
,	O
based	O
on	O
Scheme	B-Language
code	O
by	O
Stepanov	O
and	O
Kershenbaum	O
.	O
</s>
