1.9 b trees eg 03
Transcript of 1.9 b trees eg 03
B-TreesB-Trees 11
B-TreesB-Trees 22
B-TreesB-Trees 33
B-TreesB-Trees 44
B-TreesB-Trees 55
51 6242
6 12
26
55 60 7064 9045
1 2 4 7 8 13 15 18 25
27 29 46 48 53
A B-tree of order 5 containing 26 items
Note that all the leaves are at the same levelNote that all the leaves are at the same level
B-TreesB-Trees 66
1 2 8 12
B-TreesB-Trees 77
1 2
8
12 25
6, 14, 28 get added to the leaf nodes:
1 2
8
12 146 25 28
B-TreesB-Trees 88
Adding 17 to the right leaf node would over-fill it, so we take the middle key, promote it (to the root) and split the leaf
8 17
12 14 25 281 2 6
7, 52, 16, 48 get added to the leaf nodes
8 17
12 14 25 281 2 6 16 48 527
B-TreesB-Trees 99
Adding 68 causes us to split the right most leaf, promoting 48 to the root, and adding 3 causes us to split the left most leaf, promoting 3 to the root; 26, 29, 53, 55 then go into the leaves
3 8 17 48
52 53 55 6825 26 28 291 2 6 7 12 14 16
Adding 45 causes a split of 25 26 28 29
and promoting 28 to the root then causes the root to split
B-TreesB-Trees 1010
17
3 8 28 48
1 2 6 7 12 14 16 52 53 55 6825 26 29 45
B-TreesB-Trees 1111
B-TreesB-Trees 1212
B-TreesB-Trees 1313
B-TreesB-Trees 1414
B-TreesB-Trees 1515
1212 2929 5252
22 77 99 1515 2222 5656 6969 72723131 4343
Delete 2: Since there are enoughkeys in the node, just delete it
Assuming a 5-wayB-Tree, as before...
Note when printed: this slide is animated
B-TreesB-Trees 1616
1212 2929 5252
77 99 1515 2222 5656 6969 72723131 4343
Delete 52
Borrow the predecessoror (in this case) successor
5656
Note when printed: this slide is animated
B-TreesB-Trees 1717
1212 2929 5656
77 99 1515 2222 6969 72723131 4343
Delete 72Too few keys!
Join back together
Note when printed: this slide is animated
B-TreesB-Trees 1818
1212 2929
77 99 1515 2222 696956563131 4343
Note when printed: this slide is animated
B-TreesB-Trees 1919
1212 2929
77 99 1515 2222 696956563131 4343
Delete 22
Demote root key andpromote leaf key
Note when printed: this slide is animated
B-TreesB-Trees 2020
1212
292977 99 1515
3131
696956564343
Note when printed: this slide is animated
B-TreesB-Trees 2121
B-TreesB-Trees 2222
B-TreesB-Trees 2323
B-TreesB-Trees 2424