cs251-week6

cs251-week6 - Heaps A heap is a data structure that...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Heaps A heap is a data structure that implements the following functions. void insert(int key); //insert key ito the heap bool reboveMin(int &key); //put the variable key the minimum key if any, return false if heap is empty A heap is implemented with a binary tree . **The binary tree in heap has 2 properties. 1. The key in children are larger than parents left -> key > parent -> key right -> key > parent -> key unlike the previous lecture, we don't care the ordering of left and right 2. Heaps are "left filled", that is all levels are full except the last one where all the leafs are in the left side. *example 1. 8<15, child < parent , not a heap *example 2. last layer is not left filled, not a heap *example 3. internal layers are not full, not a heap example 1. 15 example 2. 8 example 3. 8 / \ / \ / 8 21 12 10 12 / \ / / / \ 10 9 21 15 21 19 **Nice characteristics of heaps: Height of a heap 1. The last layer is not full n = 4 ; height = 2 n = 2 ^(height); height = log 2 n = O(logn); 2. The last layer is full
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/04/2012 for the course CS 251 taught by Professor Staff during the Fall '08 term at Purdue.

Page1 / 3

cs251-week6 - Heaps A heap is a data structure that...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online