This preview shows pages 1–5. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: k Since a heap has height O (log n ) , downheap runs in O (log n ) time 7 6 5 9 w 5 6 7 9 w Last Updated: 06/02/12 8:32 PM CSE 2011 Prof. J. Elder  19  Arraybased Heap Implementation We can represent a heap with n keys by means of an array of length n + 1 Links between nodes are not explicitly stored The cell at rank is not used The root is stored at rank 1. For the node at rank i the left child is at rank 2 i the right child is at rank 2 i + 1 the parent is at rank floor (i/2) if 2i + 1 > n, the node has no right child if 2i > n, the node is a leaf 2 6 5 7 9 2 5 6 9 7 1 2 3 4 5 Last Updated: 06/02/12 8:32 PM CSE 2011 Prof. J. Elder  20  Merging Two Heaps We are given two heaps and a new key k We create a new heap with the root node storing k and with the two heaps as subtrees We perform downheap to restore the heaporder property 7 3 5 8 2 6 4 3 5 8 2 6 4 2 3 5 8 4 6 7...
View
Full
Document
This note was uploaded on 02/14/2012 for the course CSE 2011Z taught by Professor Elder during the Fall '11 term at York University.
 Fall '11
 Elder
 Data Structures

Click to edit the document details