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 >  
 

B. Heaps page 4 of 9

  1. Heaps are based on the notion of a complete tree. A binary tree is called completely full if all its levels are filled with nodes. A binary tree is completely full if it is of height h, and has 2h-1 nodes. Each level contains twice as many nodes as the preceding level.

  2. A binary tree is termed complete if it has no gaps on any level. The last level may have some leaves missing on the right, as shown below:

  3. A heap is a binary tree that satisfies two conditions:

    1. it is a complete tree
    2. the value in each node does not exceed any value in that node’s left and right subtrees

    Heaps are allowed to have more than one data item with the same value, and values in the left subtree do not have to be ranked lower than values in the right subtree.

  4. A heap can be used as a priority queue: the highest priority item is at the root and is trivially found. But if the root is deleted, we are left with two sub-trees and we must efficiently re-create a single tree with the heap property. The value of the heap structure is that we can both extract the highest priority item and insert a new item in O(log n) time.

 

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