Tournament sort
Tournament sort is a sorting algorithm.[src] It improves upon the naive selection sort by using a priority queue to find the next element in the sort.[src] In the naive selection sort, it takes O(n) operations to select the next element of n elements; in a tournament sort, it takes O(log n) operations (after building the initial tournament in O(n)).[src] Tournament sort is a variation of heapsort.[src]
Tournament sort is a sorting algorithm.[src] It improves upon the naive selection sort by using a priority queue to find the next element in the sort.[src] In the naive selection sort, it takes O(n) operations to select the next element of n elements; in a tournament sort, it takes O(log n) operations (after building the initial tournament in O(n)).[src] Tournament sort is a variation of heapsort.[src] import Data.Tree -- | Adapted from `TOURNAMENT-SORT!` in the Stepanov and Kershenbaum report.[src] tournamentSort :: Ord t where go [] = [] go trees = (rootLabel winner) : (go (subForest winner)) where winner = playTournament trees -- | Adapted from `TOURNAMENT!` in the Stepanov and Kershenbaum report playTournament :: Ord t playTournament trees = playTournament (playRound trees []) -- | Adapted from `TOURNAMENT-ROUND!` in the Stepanov and Kershenbaum report playRound :: Ord t playRound [tree] done = tree:done playRound (tree0:tree1:trees) done = playRound trees (winner:done) where winner = playGame tree0 tree1 -- | Adapted from `TOURNAMENT-PLAY!` in the Stepanov and Kershenbaum report playGame :: Ord t => Tree t -- ^ Input: ...[src] -> Tree t -- ^ ...[src] two trees -> Tree t -- ^ Result: `promote winner loser`, where `winner` is -- the tree with the *lesser* root of the two inputs playGame tree1 tree2 | rootLabel tree1 Tree t -- ^ The `loser` -> Tree t -- ^ Result: a tree whose root is the root of `winner` -- and whose children are: -- * `loser`, -- * all the children of `winner` promote winner loser = Node { rootLabel = rootLabel winner, subForest = loser : subForest winner} main :: IO () main = print $ tournamentSort testList where testList = [0, 1, 2, 3, 4, 5][src]
12 sentences · 12 cited inline · 0 references stored
References
No reference rows published for this article.
Cite this article
MLA
"Tournament sort." encyclopegia.org, 2026, https://encyclopegia.org/wiki/tournament-sort. Accessed 02 December 2026.
Chicago
"Tournament sort." encyclopegia.org. Accessed December 2, 2026. https://encyclopegia.org/wiki/tournament-sort.
APA
encyclopegia.org. (2026). Tournament sort. Retrieved December 2, 2026, from https://encyclopegia.org/wiki/tournament-sort
Accessed December 2, 2026 · CC BY-SA 4.0 · citation page · JSON