Next: Priority queue remove revisited
Up: Preliminaries
Previous: Preliminaries
  Index
Arrays as complete binary trees
Suppose the array to be sorted is [31, 35, 40, 10, 42]. Let us picture
this as
where the empty spaces marked
indicate that we are not
concerned with these extra entries or, indeed, how many there are of
them. Now there is nothing to prevent us from thinking of this as the
array representation of the complete binary tree
Evidently any array can be pictured in this way as a complete binary
tree. The problem is that it is not a heap, as it stands, since it
fails to satisfy the heap order property. Fortunately there is an
efficient algorithm for restoring heap order, which we can apply to
the original array. The original array will then play the part of our
working binary heap, without the need for auxiliary storage.
Peter Williams
2005-06-07