1.9 b trees eg 03

24
B-Trees B-Trees 1

Transcript of 1.9 b trees eg 03

Page 1: 1.9 b trees eg 03

B-TreesB-Trees 11

Page 2: 1.9 b trees eg 03

B-TreesB-Trees 22

Page 3: 1.9 b trees eg 03

B-TreesB-Trees 33

Page 4: 1.9 b trees eg 03

B-TreesB-Trees 44

Page 5: 1.9 b trees eg 03

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

Page 6: 1.9 b trees eg 03

B-TreesB-Trees 66

1 2 8 12

Page 7: 1.9 b trees eg 03

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

Page 8: 1.9 b trees eg 03

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

Page 9: 1.9 b trees eg 03

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

Page 10: 1.9 b trees eg 03

B-TreesB-Trees 1010

17

3 8 28 48

1 2 6 7 12 14 16 52 53 55 6825 26 29 45

Page 11: 1.9 b trees eg 03

B-TreesB-Trees 1111

Page 12: 1.9 b trees eg 03

B-TreesB-Trees 1212

Page 13: 1.9 b trees eg 03

B-TreesB-Trees 1313

Page 14: 1.9 b trees eg 03

B-TreesB-Trees 1414

Page 15: 1.9 b trees eg 03

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

Page 16: 1.9 b trees eg 03

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

Page 17: 1.9 b trees eg 03

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

Page 18: 1.9 b trees eg 03

B-TreesB-Trees 1818

1212 2929

77 99 1515 2222 696956563131 4343

Note when printed: this slide is animated

Page 19: 1.9 b trees eg 03

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

Page 20: 1.9 b trees eg 03

B-TreesB-Trees 2020

1212

292977 99 1515

3131

696956564343

Note when printed: this slide is animated

Page 21: 1.9 b trees eg 03

B-TreesB-Trees 2121

Page 22: 1.9 b trees eg 03

B-TreesB-Trees 2222

Page 23: 1.9 b trees eg 03

B-TreesB-Trees 2323

Page 24: 1.9 b trees eg 03

B-TreesB-Trees 2424