lec9 - MIT OpenCourseWare http:/ocw.mit.edu 6.006...

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

View Full Document Right Arrow Icon
MIT OpenCourseWare http://ocw.mit.edu 6.006 Introduction to Algorithms Spring 2008 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms .
Background image of page 1

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

View Full DocumentRight Arrow Icon
Lecture 9 Sorting II: Heaps 6.006 Spring 2008 Lecture 9: Sorting II: Heaps Lecture Overview Review: Heaps and MAX HEAPIFY Building a Heap Heap Sort Priority Queues (Recitation) Readings CLRS 6.1-6.4 Review Heaps: Parent( i ) = i/ 2 ± Left( i ) = 2 i Right( i ) = 2 i + 1 Max heap property: A[Parent( i )] A[ i ] MAX HEAPIFY( A, 2) heap size( A ) = 10 A [2] A [4] ←→ MAX HEAPIFY(A,4) A [4] A [9] ←→ 1
Background image of page 2
Lecture 9 Sorting II: Heaps 6.006 Spring 2008 Violation 16 10 9 3 4 14 7 1 8 2 1 2 3 4 5 6 7 10 9 8 16 4 14 7 9 3 2 8 1 10 1 2 3 4 5 6 7 8 9 10 etc O(lg n) time Figure 1: Review from last lecture Building a Heap A [1 n ] converted to a max heap Observation : Elements A [ n/ 2 + 1 ±··· n ] are all leaves ··· of the tree and can’t have children. BUILD
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 09/24/2010 for the course CS 6.006 taught by Professor Erikdemaine during the Spring '08 term at MIT.

Page1 / 7

lec9 - MIT OpenCourseWare http:/ocw.mit.edu 6.006...

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