lec04 - 6.006- Introduction to Algorithms Lecture 4 Prof....

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

View Full Document Right Arrow Icon
6.006- Introduction to Algorithms Lecture 4 Prof. Piotr Indyk
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 Overview Review: Binary Search Trees Importance of being balanced Balanced BSTs – AVL trees • definition • rotations, insert 1 5 6 7 10 12 7 10 5 1 6 12
Background image of page 2
Binary Search Trees (BSTs) Each node x has: – key[x] – Pointers: left[x], right[x], p[x] Property: for any node x : – For all nodes y in the left subtree of x : key[y] key[x] – For all nodes y in the right subtree of x : key[y] key[x] 10 12 5 1 6 7 root leaf height = 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
The importance of being balanced h = Θ (log n) h = Θ (n) for n nodes: 1 5 6 7 10 12 7 10 5 1 6 12
Background image of page 4
Balanced BST Strategy Augment every node with some data Define a local invariant on data Show (prove) that invariant guarantees Θ (log n) height Design algorithms to maintain data and the invariant
Background image of page 5

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

View Full DocumentRight Arrow Icon
AVL Trees: Definition Data : for every node, maintain its height (“augmentation”) – Leaves have height 0 – NIL has “height” -1 Invariant : for every node x , the
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/11/2011 for the course MATH 180 taught by Professor Byrns during the Spring '11 term at Montgomery College.

Page1 / 22

lec04 - 6.006- Introduction to Algorithms Lecture 4 Prof....

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

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