next up previous index
Next: Arithmetic of Tree Traversal Up: Binary Heaps and Priority Previous: Complete Binary Trees   Index


Array Representation

A complete binary tree has a simple array representation. Suppose we number the nodes from left to right, beginning at the top and ending at the bottom. Then we can store the various data items in the corresponding elements of an array. For example

\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}
can be represented by the array

\begin{picture}(800,120)(0,-20)
\put(0,0){\line(1,0){800}}
\put(0,100){\line(1...
...){\makebox(0,0){\small 6}}
\put(750,-35){\makebox(0,0){\small 7}}
\end{picture}
This in fact corresponds to the level order enumeration of the tree. Note that we only use an initial segment of the array. Provided the array is long enough, and we know the number of tree nodes, it doesn't matter how many unused components there are at the end.



Subsections

Peter Williams 2005-06-07