
B-Tree Data Structure 565
OrderedCollection
Correctness Highlights: The inherited public insert method preserves SIZE. It is easily verified
that when the collection is empty, the method creates a B-tree that adheres to all properties.
By INORDER the leaf node where element should be inserted is obtained. (When there are
duplicates, we have chosen to insert the new element after all equivalent elements in the iteration
order.) The rest of the correctness follows from the BTreeNode add method.
If a top-down insertion is preferred, then the while loop in the insert method would be replaced
by:
while (ptr.atMaxSize() || !ptr.isLeaf() ) {
curIndex = ptr.data.findLastInsertPosition(0, ...