Content deleted Content added
Line 65:
The tournament tree<ref>
{{cite book| last = Knuth| first = Donald| authorlink = Donald Knuth| series = [[The Art of Computer Programming]]| volume= 3| title= Sorting and Searching| edition = 2nd| publisher = Addison-Wesley| year= 1998| chapter = Chapter 5.4.1. Multiway Merging and Replacement Selection| pages = 158–168| isbn = 0-201-89685-0| ref = harv}}</ref>
Every leaf stores a pointer
For the k-th leaf the value is the value that its pointer points to and the index is k.
For every internal leaf the value is the minimum of the values of the node's children.
The index of an internal leaf indicates which input array the value comes from.
The root of the tournament tree contains the smallest element and the index of the corresponding input array.
The algorithm iteratively transfers this element and advances the corresponding pointer.
It then updates the values of the nodes on the path from the corresponding leaf to the root.
As the tree is balanced, this path contains only Θ(log k)
As there n elements that need to be extracted, the resulting total running time is Θ(n log k).
===== Example =====
|