Lecture18

Lecture18 - Lecture 18 Heaps CS2134 Priority Queues...

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

View Full Document Right Arrow Icon
CS2134 Lecture 18 Heaps
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
CS2134 PQ operations on heaps findMin: easy, min element is at root
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
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 Right Arrow Icon
Ask a homework question - tutors are online