This preview shows page 1. Sign up to view the full content.
Unformatted text preview: re in Array[3..6].
a This is great for a balanced tree. But if the tree is
not balanced, many elements of the array are not
used. 8 nodes = array of 23. 2 1 2 1
3 z 14 Left child of node i is node 2*i+1
Right child is node 2*i+2
Right child is node 2*i+2 x 1
y The parent of node i is node (i-1)/2
(i- Although we now do not need two child pointers
to move either down or up the tree, we do need
some indicator of missing nodes.
This can either be a sentinel value of the stored
data, or we could have a second array indicating
which nodes are occupied.
So we're only just saving space. t 4
v w The parent of the last node j is (j-1)/2.
(jCall this value nlast.
nlast 0 r 10 9
s 19 20 22 There is, however, one data structure which uses
a fully loaded binary tree and hence is optimally
stored in an array.
It is called a heap.
It has one property to determine the relative
positions of data:
the data value at the root of a heap is larger than
all of its children. 17 As a subtree is also a tree, so the subtree of...
View Full Document