Lecture 09
Lecture 09
CSE 373
Data Structures
Lecture 9
Readings
• Reading
› Sections 4.5-4.7
G G G G
P P P P
X X X X
Zig-zig
G 4
P 5 G 5
Zig-zag
X 2 1 P
ZigFromLeft
ZigFromRight
(ZigFromRight) (ZigFromLeft)
ZigZagFromLeft
(ZigFromLeft) (ZigFromLeft)
ZigZigFromLeft
Find(T) Find(R)
1 1
ZigFromRight
2 1 2
2 1
3
3 2 ZigFromRight
2
1 3
1
4 3
4
2 4 ZigFromRight
3
1
2
1
Each Insert takes O(1) time therefore O(n) time for n Insert!!
2 8 13 20 2 6 9 15
13 20
6 9
Splay (zig) remove
6
attach 5 10
5 10
15 2 6 9 15
2 9
13 20 13 20
1/31/03 Splay Trees and B-Trees - Lectur 17
e9
Analysis of Splay Trees
• Splay trees tend to be balanced
› M operations takes time O(M log N) for M > N
operations on N items. (proof is difficult)
› Amortized O(log n) time.
• Splay trees have good “locality” properties
› Recently accessed items are near the root of the
tree.
› Items near an accessed one are pulled toward the
root.
6:11 17:-
3 4 6 7 8 11 12 13 14 17 18
• Search for 8
1/31/03 Splay Trees and B-Trees - Lectur 19
e9
B-Trees
B-Trees are multi-way search trees commonly used in database
systems or other applications where data is stored externally on
disks and keeping the tree shallow is important.
T1 ... Ti ... TM
3 4 6 7 8 11 12 13 14 17 18
13:-
6:11 17:-
3 4 6 7 8 11 12 13 14 17 18
13:-
6:11 17:-
3 4 6 7 8 11 12 13 14 17 18