lec6 - Outline Heap Array representation Heap operation...

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

View Full Document Right Arrow Icon
Outline Heap — Array representation Heap operation — GetMax Heap operation — Insert Heap operation — Heap construction Heapsort Heap operation — Heap construction (ver 2) Applications about heaps Sorting massive data sets: d-way merge Lecture 6, Heap and Heapsort p. 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
Array representation Root position: index 1 Left position: index 2 i Right position: index 2 i + 1 Traverse in the tree, by calculations on in- dices Properties the largest is at index 1 a complete binary tree height of the tree: O (log n ) length of root-to-leaf path: O (log n ) Lecture 6, Heap and Heapsort p. 2
Background image of page 2
Insert, (bottom-up heapify), implemented as swim in [Sedgewick] OO style The priority queue is stored in array p The size of the queue is n insert(v) n + +; p [ n ] v ; k n while ( k > 1 and p [ k/ 2] < p [ k ]) swap p [ k/ 2] and p [ k ] k k/ 2 Classical style (more commonly used by theoretical people) insert(p, v) p.n
Background image of page 3

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

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

This note was uploaded on 07/17/2010 for the course CS 240 taught by Professor Ortiz during the Spring '09 term at Waterloo.

Page1 / 7

lec6 - Outline Heap Array representation Heap operation...

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

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