AVL Trees
Monday, February 21, 2011
4:08 PM
AVL Tree Node
•
Parent
•
Left
•
Data
•
Right
•
Balance factor
1.
Search: same as BST
2.
Insert
o
Rebalancing at node x
•
Let Q be child of x in its taller side (Q is root of taller subtree of x)
•
Case 1: Balance factor of x = balance factor of Q
Action: Rotate qx
•
Q becomes new root
O(1) [# of pointer changes is independent of # nodes in tree]
•
Case 2: Balance factor of x != balance factor of Q
Let R be root of taller subtree of Q
Rotate RQ
Rotate RX
Search time O(log n)
•
# of levels is O(log n)
•
Hash Tables
Monday, February 28, 2011
3:42 PM
Array access = O(1)
Start with simplified/small range of keys
Key=index
This makes searching O(1) since the key is the index in the array
Space usage= # of objects in set/range of keys
How to fix memory issues?
•
Simplify key so all items can fit in affordable 'table' size
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document•
Manipulate key
•
Key>hash function>index in array
•
Store an array of linked lists keys with same indexes get stored in the same linked lists
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '09
 VENUGOPAL
 hash function, Hashcode

Click to edit the document details