12 Splay Trees

# 12 Splay Trees - Self-adjusting Trees 15-211 Fundamental...

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

Self-adjusting Trees 15-211: Fundamental Data Structures and Algorithms Charlie Garrod 23 February 2010 Reading for today: Weiss 22

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

View Full Document
2 Announcements HW3 theory due now Programming due Thursday night Quiz 3 in recitation tomorrow Midterm in lecture next Tuesday Handwritten note sheet, 1 page front+back Review session Sunday, 2 pm, location TBA Please review the cheating policy: http://www.cs.cmu.edu/~211/policy/cheating.html
3 Last time: 2-3-4 trees Insert(B) S W G Q H A C F S W H A B C G Q F

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

View Full Document
4 Last time: Red-black trees Each 2-3-4 node corresponds to one black node 2-3-4 node splits correspond to rotations and recolorings B F H D I G G F B H I D D I OR
5 Case 1: single right rotation X y A B C X y A B C (to be continued…)

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

View Full Document
6 Case 1: single right rotation X y A B C X y A B C
7 Case 2: double right rotation X y A C D Z B X y A C D Z B (to be continued…)

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

View Full Document
8 Case 2: double right rotation X y A C D Z B X y A C D Z B
9 Dealing with imbalance Balanced trees Maintain structural invariants that guarantee O(lg n ) height AVL trees 2-3-4 and Red-black trees Self-adjusting trees Not necessarily O(lg n ) height, but can show amortized efficiency

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

View Full Document
10 90-10 rule 90% of the accesses go to 10% of the data
11 Today: Self-adjusting trees Rotate-to-root Splay trees Bottom-up splay operation Using splay Top-down splay operation

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

View Full Document
12 Rotate-to-root When you access a node, use rotations to move it to the root e.g., find (7) 1 3 2 4 6 5 7 1 3 2 4 6 5 7
13 Rotate-to-root When you access a node, use rotations to move it to the root e.g., find (7) 1 3 2 4 6 5 7 1 3 2 4 6 5 7 1 3 2 4 6 7 5

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

View Full Document
14 Rotate-to-root When you access a node, use rotations to move it to the root e.g., find (7) 1 3 2 4 6 5 7 1 3 2 4 6 5 7 1 3 2 4 6 7 5 1 3 2 7 6 4 5 1 7 2 3 6 4 5 1 2 7 3 6 4 5 7 2 1 3 6 4 5
Rotate-to-root When you access a node, use rotations to move it to the 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.

{[ snackBarMessage ]}

### Page1 / 60

12 Splay Trees - Self-adjusting Trees 15-211 Fundamental...

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

View Full Document
Ask a homework question - tutors are online