Data Structures and Algorithms
with Object-Oriented Design Patterns in C# |
A binomial queue that contains n items consists of at most binomial trees. Each of these binomial trees is heap ordered. In particular, the smallest key in each binomial tree is at the root of that tree. So, we know that the smallest key in the queue is found at the root of one of the binomial trees, but we do not know which tree it is.
The MinTree property get accessor is used to determine which of the binomial trees in the queue has the smallest root. As shown in Program , the MinTree simply traverses the entire linked list to find the tree with the smallest key at its root. Since there are at most binomial trees, the worst-case running time of MinTree is
Program: BinomialQueue class MinTree and Min methods.
Program also defines the Min property get accessor that returns the smallest key in the priority queue. The Min property uses the MinTree property to locate the tree with the smallest key at its root and returns that key. Clearly, the asymptotic running time of the Min accessor is the same as that of the MinTree accessor.