# lec09 - 6.006 Introduction to AlgorithmsLecture 9 Prof...

This preview shows pages 1–6. Sign up to view the full content.

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

View Full Document

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

View Full Document

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 6.006- Introduction to AlgorithmsLecture 9 Prof. Piotr Indyk Menu •Priority Queues •Heaps •Heapsort Priority Queue A data structure implementing a set Sof elements, each associated with a key, supporting the following operations: increase_key(S, x, k) : insert element xinto set Sreturn element of Swith largest key return element of Swith largest key and remove it from Sincrease the value of element x’ s key to new value k (assumed to be as large as current value) insert(S, x) : max(S) : extract_max(S) : 41 46 49.1 56 time (mins) Lecture 3: Heap •Implementation of a priority queue (more efficient than BST) •An array, visualized as a nearly complete binary tree •Max Heap Property: The key of a node is ≥than the keys of its children (Min Heap defined analogously) All my arrays start at index 1 Heap as a Tree root of tree: first element in the array, corresponding to i = 1 parent(i) =i/2: returns index of node's parent left(i)=2i: returns index of node's left child right(i)=2i+1: returns index of node's right child...
View Full Document

{[ snackBarMessage ]}

### Page1 / 23

lec09 - 6.006 Introduction to AlgorithmsLecture 9 Prof...

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

View Full Document
Ask a homework question - tutors are online