Data Structures and Algorithms with Object-Oriented Design Patterns in C#
next up previous contents index

AddTree and RemoveTree

The AddTree and RemoveTree methods of the BinomialQueue class facilitate the implementation of the various priority queue operations. These methods are defined in Program gif. The AddTree method takes a BinomialTree and appends that tree to treeList. AddTree also adjusts the count in order to keep track of the number of items in the priority queue. It is assumed that the order of the tree which is added is larger than all the others in the list and, therefore, that it belongs at the end of the list. The running time of AddTree is clearly O(1).

   program26877
Program: BinomialQueue class AddTree and RemoveTree methods.

The RemoveTree method takes a binomial tree and removes it from the list. It is assumed that the specified tree is actually in the list. RemoveTree also adjust the count as required. The running time of RemoveTree depends on the position of the tree in the list. A binomial queue which contains exactly n items altogether has at most tex2html_wrap_inline66101 binomial trees. Therefore, the running time of RemoveTree is tex2html_wrap_inline59121 in the worst case.


next up previous contents index

Bruno Copyright © 2001 by Bruno R. Preiss, P.Eng. All rights reserved.