Lecture18

# Lecture18 - Lecture 18 Heaps CS2134 Priority Queues...

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

CS2134 Lecture 18 Heaps

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

View Full Document
CS2134 Priority Queues Sometimes want non-FIFO queues in which elements with higher priority are retrieved before those with lower priority Elements have priority numbers low number means high priority Operations: findMin: returns the smallest element deleteMin: removes the smallest element insert: adds an element These can be supported efficiently with a data structure called a heap Can also be used for a nice sorting algorithm
CS2134 Heaps Complete binary tree: binary tree in which all levels are “full”, except for possibly bottom level which is filled in from the left h = O(log n) where h is height and n is size A heap is a complete binary tree in which every node satisfies the heap property: parent(x) <= x Observe smallest node is at the root heap is NOT Binary Search Tree

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

View Full Document
CS2134 100 10 30 20 60 40 80 70 90 50 -inf 10 30 20 60 40 80 70 100 90 50 0 1 2 3 4 5 6 7 8 9 10
CS2134 PQ operations on heaps findMin: easy, min element is at root

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.

## This note was uploaded on 12/09/2009 for the course CS 2134 taught by Professor Hellerstein during the Spring '07 term at NYU Poly.

### Page1 / 8

Lecture18 - Lecture 18 Heaps CS2134 Priority Queues...

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

View Full Document
Ask a homework question - tutors are online