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

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

6.006- Introduction to Algorithms Lecture 4 Prof. Piotr Indyk

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

View Full Document
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
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

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

View Full Document
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
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

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

View Full Document
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
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
Ask a homework question - tutors are online