Skip to main content
ICT
Lesson AB33 - PriorityQueues
 
Main Previous Next
Title Page >  
Summary >  
Lesson A1 >  
Lesson A2 >  
Lesson A3 >  
Lesson A4 >  
Lesson A5 >  
Lesson A6 >  
Lesson A7 >  
Lesson A8 >  
Lesson A9 >  
Lesson A10 >  
Lesson A11 >  
Lesson A12 >  
Lesson A13 >  
Lesson A14 >  
Lesson A15 >  
Lesson A16 >  
Lesson A17 >  
Lesson A18 >  
Lesson A19 >  
Lesson A20 >  
Lesson A21 >  
Lesson A22 >  
Lesson AB23 >  
Lesson AB24 >  
Lesson AB25 >  
Lesson AB26 >  
Lesson AB27 >  
Lesson AB28 >  
Lesson AB29 >  
Lesson AB30 >  
Lesson AB31 >  
Lesson AB32 >  
Lesson AB33 >  
Vocabulary >  
 

D. Storage of Complete Trees page 6 of 9

  1. The properties of a complete tree lead to a very efficient storage mechanism using n sequential locations in an array.

  2. An important benefit of the array representation is that we can move around the tree, from parent to children or from child to parent, by simple arithmetic. If we number the nodes from 1 at the root then

    1. the left and right children of node i, if they are present, are at 2i and 2i+1
    2. the parent of node i is at i/2 (truncated to an integer)

  3. If items is the array, the root corresponds to Items[1]; subsequent slots in the array store the nodes in each consecutive level from left to right.

  4. In a Java implementation, it is convenient to leave Items[0] unused. With this numbering of nodes, the children of the node Items[i] can be found in Items[2*i] and Items[2*i+1], and the parent of Items[i] is in Items[i/2].

 

Main Previous Next
Contact
 © ICT 2006, All Rights Reserved.