Data Structures in Java
Session 10 Instructor: Bert Huang http://www1.cs.columbia.edu/~bert/courses/3134
Data Structures in Java Session 10 Instructor: Bert Huang - - PowerPoint PPT Presentation
Data Structures in Java Session 10 Instructor: Bert Huang http://www1.cs.columbia.edu/~bert/courses/3134 Announcements Homework 3 due 10/20 Review AVL Trees Single rotate for left-left imbalance Double rotate for left-right
Session 10 Instructor: Bert Huang http://www1.cs.columbia.edu/~bert/courses/3134
running time of each operation
run provably faster than O(M f(N))
running time, aka amortized
running time of many operations
chooses input values and operations
randomization scheme
search tree property
that node the new root of the tree
more spread out
tends to be accessed often.
rotation
and there are two cases
left child (or left-right)
a b c w x y z a b c w x y z
strategy like AVL trees
weʼll compare this to single-rotation
a b c y w x z a b c y w x z
6 5 4 3 2 1 7 6 5 4 3 2 1 7
zig-zig single-rotate
6 5 4 3 2 1 7
6 5 4 3 2 1 7
zig-zig single-rotate
6 5 4 3 2 1 7
6 5 4 3 2 1 7
zig-zig single-rotate
6 5 4 3 2 1 7
6 5 4 3 2 1 7
zig-zig single-rotate
make the tree its left child
can only bad operations once before they become cheap
O(log N) per operation (fyi, not proved)
via keys
letter
Root c d
b u
cat cow dog doberman duck
length k or (looking up) is O(k)
shocking!)
like dictionaries