Lably
Skip to content

Tournament sort

Sorting algorithm

  • 7 min read
  • 3 chapters

Related on Lably

Through Big O notation and Scheme (programming language)

Common application

Tournament replacement selection sorts are used to gather the initial runs for external sorting algorithms. Conceptually, an external file is read and its elements are pushed into the priority queue until the queue is full. Then the minimum element is pulled from the queue and written as part of the first run. The next input element is read and pushed into the queue, and the min is selected again and added to the run. There's a small trick that if the new element being pushed into the queue is less than the last element added to the run, then the element's sort value is increased so it will be part of the next run. On average, a run will be 100% longer than the capacity of the priority queue.

Tournament sorts may also be used in N-way merges.

Sign in to keep reading

2 more chapters are free with a Lably account.

More in Computing and communication