Next: Complete Binary Trees
Up: Data Structures
Previous: Code and demonstration
  Index
Binary Heaps and Priority Queues
When discussing binary search trees we looked at examples like
where the items are placed in the tree so that
- (S)
- the value stored at each node of the tree is greater than
the values stored in its left subtree, and less than the values stored
in its right subtree.
You can think of the items as being ordered from left to right.
We obtain an interesting alternative structure if the items are
ordered from bottom to top. Here is an example:
The defining property is now that
- (H)
- the value stored at each node of the tree is greater than
or equal to the values stored in its left subtree, and greater than or
equal to the values stored in its right subtree.
Note that the value at a node is now greater than or equal to the
values in both subtrees. (We are now also allowing
duplicates, though there are none in this case).
A simple local test for whether property (H) holds is that the value
stored at every node should be no greater than the value stored at its
parent (apart from the root which doesn't have a parent). It follows
that every path from the root to a leaf forms a decreasing
(non-increasing) sequence.
Subsections
Next: Complete Binary Trees
Up: Data Structures
Previous: Code and demonstration
  Index
Peter Williams
2005-06-07