next up previous index
Next: Array Representation Up: Binary Heaps and Priority Previous: Binary Heaps and Priority   Index


Complete Binary Trees

Trees satisfying property (H) are particularly useful if they are well balanced, in the sense of having short path lengths from root to leaves. They don't have to be quite as well balanced as the tree above. All we require is that the path lengths are as short as possible. For example, we could have

\begin{picture}(200,135)(-100,60)
\put(0,180){\makebox(0,0){42}}
\put(-60,120)...
...){20}}
\put(28,72){\line(2,3){20}}
\put(-28,72){\line(-2,3){20}}
\end{picture}
or

\begin{picture}(200,135)(-100,60)
\put(0,180){\makebox(0,0){42}}
\put(-60,120)...
...{36}}
\put(-92,72){\line(2,3){20}}
\put(-28,72){\line(-2,3){20}}
\end{picture}
or even

\begin{picture}(200,135)(-100,60)
\put(0,180){\makebox(0,0){42}}
\put(-60,120)...
...{36}}
\put(50,130){\line(-1,1){36}}
\put(-92,72){\line(2,3){20}}
\end{picture}
But we don't want are trees like

\begin{picture}(200,190)(-70,0)
\put(0,180){\makebox(0,0){21}}
\put(-60,120){\...
...){20}}
\put(-12,12){\line(2,3){20}}
\put(52,12){\line(-2,3){20}}
\end{picture}
in which there are paths from some leaf to the root whose lengths differ by more than 1. We want trees in which every level is fully occupied except, possibly, for the bottom level.

It is also very convenient, as you will see, if the bottom level is filled from left to right. (It could alternatively be filled from right to left, but we need to agree on one or the other.) Binary trees of this type are called complete. They are defined as being completely filled, except possibly for the bottom level, which is filled from left to right. A complete binary tree which also satisfies the ordering property (H) is called a binary heap.


next up previous index
Next: Array Representation Up: Binary Heaps and Priority Previous: Binary Heaps and Priority   Index
Peter Williams 2005-06-07