Tournament Sort
This page provides a brief introduction to tournament sort.
Definition
Tournament sort, also known as tree selection sort, is an optimized version of selection sort and a variant of heap sort (both using a complete binary tree). It improves upon selection sort by using a priority queue to find the next element to select.
Introduction
The name "tournament sort" comes from the single-elimination competition format. In such a format, many participants compete in pairwise matches, with winners advancing to the next round. This elimination method can determine the best participant, but the participant eliminated in the final round may not be the second-best—they might be inferior to some previously eliminated participants.
Process
Taking the minimum tournament sort tree as an example:

The elements to be sorted are those displayed at the leaf nodes. The red edges show the winning paths of the smaller elements in each round of comparison. Clearly, completing one "tournament" can select the smallest element from a group.
After each round of comparing \(n\) elements, \(\frac{n}{2}\) "winners" are obtained, with the smaller element from each pair advancing to the next round. If a pair cannot be formed, the element directly advances to the next round.

After completing one "tournament," the selected element must be removed. This is done by setting it to \(\infty\) (similar to heap sort), and then holding another "tournament" to select the next smallest element.
This process is repeated until all elements are sorted.
Properties
Stability
Tournament sort is an unstable sorting algorithm.
Time Complexity
The best-case, average-case, and worst-case time complexities of tournament sort are all \(O(n\log n)\). It takes \(O(n)\) time to initialize the "tournament" and \(O(\log n)\) time to select one element from \(n\) elements.
Space Complexity
The space complexity of tournament sort is \(O(n)\).
Implementation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
External Links
本页面最近更新:,更新历史
发现错误?想一起完善? 在 GitHub 上编辑此页!
本页面贡献者:OI-wiki
本页面的全部内容在 CC BY-SA 4.0 和 SATA 协议之条款下提供,附加条款亦可能应用