• Study Resource
• Explore

Survey

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Transcript
```EECS 311: Chapter 4 Notes
Chris Riesbeck
EECS Northwestern
 Unless otherwise noted, all tables,
graphs and code from Mark Allen
Weiss' Data Structures and Algorithm
2006 by Pearson Education, Inc.
Binary Search Trees
Binary
Search
Tree
Not a
Binary
Search
Tree
BST with = left/right depths
AVL Trees
AVL Tree
Not AVL
Tree
Right Rotation
Parent pointer to
k2…
changed to point
to k1
becomes left
subtree
Right subtree
of of k2
k1…
Rotate right when
left left subtree
too deep
Left Rotation
Rotate left when
right right subtree
too deep
Left-Right Rotation
When right
subtree of left
subtree too deep
…then rotate k2
right through k3
Rotate k2 left
through k1 first…
Red-Black Trees
 AVL-style rotations to balance
 No numbers, just one red-black bit
 Use rotations and recoloring to
guarantee:
 Never two red nodes in a row
 All leaves same depth counting black
nodes
Rotations in Red-Black Trees
Recoloring in Red-Black Trees
Splay Tree





Balance on access, not insertion
Use AVL-style rotations
Move item just accessed to the root
Typically makes tree shallower
Complexity
 Can be O(N) worst case single access
 O(M log N) on for M accesses
 Amortized O(log N)
 No bookkeeping data needed
Zig-zag Rotation
Zig-zig Rotation
B-Trees




No rotations
N-way tree (N subtrees, N-1 keys)
Keys sorted in each node
When passing through a full node:
 Make a new node
 Move the keys and pointers on the right to the
new node
 Move middle key and the pointer to the new
node to parent node
 Note: parent can't be full. Why?