cse 100: b trees (contd) -...
TRANSCRIPT
CSE 100: B TREES (CONTD)
CAPES and End of year survey • Have you filled out the CAPE form? A. Yes B. No Deadline Mon Dec 15th
Insertion and properties of B-trees
13
2 8 21 25 33 50
Insert 15 into this B-tree
Insertion and properties of B-trees
13 25
2 8 15 21 33 50
Insert 22 and 23
Insertion and properties of B-trees
13 25
2 8 15 21 22 23 33 50
Insert 16
Insertion and properties of B-trees
13 21 25
2 8 15 16 33 50
Insert 16, after
22 23
Insertion and properties of B-trees
13 25 60 85
2 8 15 21 33 50 61 68 75 80 90 95 99
Insert 62
True or false: after the insert, the leaves will be at different levels A. True B. False
Insertion and properties of B-trees
13 25 60 85
2 8 15 21 33 50 61 68 75 80 90 95 99
Insert 62
Which key will be promoted up? A. 61 B. 62 C.68 D. 75 E. 80
Insertion and properties of B-trees
13 25 60 85
2 8 15 21 33 50
61 62
90 95 99
Insert 62
Which key will be promoted up? A. 13 B. 25 C.60 D. 85 E. 68
75 80
Insertion and properties of B-trees
13 25
2 8 15 21 33 50
61 62
90 95 99
Insert 62 75 80
68 85 13 25 60 85
Insertion and properties of B-trees
B-trees grow up! (Which is why all their leaves are always at the same level)
13 25
2 8 15 21 33 50
75 80 90 95 99
68 85
60
61 62
Inser&on and proper&es of B-‐trees
B-trees grow up! (Which is why all their leaves are always at the same level)
13 25
2 8 15 21 33 50
75 80 90 95 99
68 85
60
61 62
What is the &me to find an element in a B-‐tree of order M with N keys?
• What is the maximum height of the tree in terms of M and N?
13 25
2 8 15 21 33 50
75 80 90 95 99
68 85
60
61 62
Exact expression for the worst case &me to find an element in a B-‐tree of order M with N keys?
• Maximum height: log M/2 N • Given
– Tm is the time to access an element in memory – Td is the time to access an element on disk
13 25
2 8 15 21 33 50
75 80 90 95 99
68 85
60
61 62
Exact expression for the worst case &me to find an element in a B-‐tree of order M with N keys?
• Maximum height: log M/2 N • Given
– Tm is the time to access an element in memory – Td is the time to access an element on disk
• Time to find an element: Tm log M * log M/2 N + Td log M/2 N
What is the worst case big O run time of find? A. O(log2 M) B. O(log2 N) C. Neither
B-‐Tree performance • Worst case O (log2N) which doesn’t reflect their true
benefit • The time savings in a B-Tree comes from efficiently
reading lots of data from disk • When B-Trees are stored in memory they are
typically comparable to other search trees • When they have to access disk they are a big win
(2-‐3-‐4) B-‐trees
3 5 8
1 2 4 6 7 14 15
13
10
11 12 9
(2-‐3-‐4) B-‐trees == RBTs!
3 5 8
1 2 4 6 7 14 15
13
10
11 12 9
(2-‐3-‐4) B-‐trees == RBTs!
3 5 8
1 2 4 6 7 14 15
13
10
11 12 9
10
5 13
3 8
7
6
9 4 2
1
12
11
15
14
So which are asymptotically faster? RB-trees or 2-3-4 (B) trees? A. RB trees B. B-trees C. They are the same
B-‐Tree performance • Refer Paul Kube’s slides http://cseweb.ucsd.edu/users/kube/cls/100/Lectures/lec17/lec17.pdf