1 / 39

B-Tree’s It’s not your typical Binary Tree (it’s not even Binary)

B-Tree’s It’s not your typical Binary Tree (it’s not even Binary). B-Tree. Task : Given a large amount of data that does not fit into main memory, process it into a dictionary data structure • Need to minimize number of disk accesses • With each disk read, read a whole block of data

emma-parks
Download Presentation

B-Tree’s It’s not your typical Binary Tree (it’s not even Binary)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. B-Tree’s It’s not your typical Binary Tree (it’s not even Binary)

  2. B-Tree • Task: Given a large amount of data that does not fit into main memory, process it into a dictionary data structure • • Need to minimize number of disk accesses • • With each disk read, read a whole block of data • • Construct a balanced search tree that uses one disk block per tree node • • Each node needs to contain more than one key

  3. B-Tree k-ary search trees

  4. B-Tree Example of a 4-ary tree

  5. B-Tree Example of a 4-ary search tree

  6. B-Tree

  7. B-Tree

  8. B-Tree

  9. B-Tree

  10. B-Tree

  11. B-Tree

  12. B-Tree

  13. B Tree Insertion (ID)‏ Suppose we want to insert 60 into this order 3 B-Tree Starting at the root: 10 < 60 < 88, so we look to the middle child. Since this is a leaf and there is room, we simply add 60. Order 3 B-Tree Insertion Example 1

  14. B Tree Insertion (ID)‏ Now we will insert 66 Starting at the root: 10 < 66 < 88, so we look to the middle child. But this leaf is full. We will need to split the leaf node around 60 and try to add 60 to the leaf's parent. But its parent is the root, and it is full. We will need to split the root. Order 3 B-Tree Insertion Example 2

  15. B Tree Insertion (ID)‏ Since the root is full, we will split it around 60. The node with 60 is now the root. This concludes the insertion of 66. Order 3 B-Tree Insertion Example 2

  16. B Tree Insertion (ID)‏ Now we will insert 21 into the tree Starting at the root: 21 < 60, so we follow the first link to 10. Since 10 < 21, we then follow the second link to the leaf with 57. There is room in the leaf, so we add 21 and are done. Order 3 B-Tree Insertion Example 3

  17. B Tree Insertion (ID)‏ Now we will insert 98 From the root, 60 < 98, so we follow the second link to 88. Since 88 < 98, we then follow the second link to the leaf with 97. There is room in the leaf, so we add 97 and are done. Order 3 B-Tree Insertion Example 4

  18. B Tree Insertion (ID)‏ Now we will perform the same insertions for an order 4 B-Tree with the same values. We start by trying to insert 60. Since 60 < 88, we follow the left link. This leaf is already full, so will need to perform a split. Order 4 B-Tree Insertion Example 1

  19. B Tree Insertion (ID)‏ We will split the node around 57. Then try to add 57 to its parent. In this case, the parent is the root. The root has room, so we add 57 and are done. This concludes the insertion of 60. Order 4 B-Tree Insertion Example 1

  20. B Tree Insertion (ID)‏ Now we will insert 66 From the root, 57 < 66 < 88, so we follow the middle link. There is room in this leaf, so add 66 and we are done. Order 4 B-Tree Insertion Example 2

  21. B Tree Insertion (ID)‏ Next we will insert 21 From the root, 21 < 57, so we follow the first link. Since this is a 4th order tree, there is room in this leaf. We add 21 and we are done. Order 4 B-Tree Insertion Example 3

  22. B Tree Insertion (ID)‏ Now we insert 98 From the root, 57 < 98, so we follow the rightmost link. There is room in this leaf, so we add 98 and we are done. Order 4 B-Tree Insertion Example 4

  23. B Tree Insertion (name)‏ Next we'll try some examples using names instead of numbers. We will start with this order 4 B-Tree. Let's add [Shaffer, Clifford] to this tree. Order 4 B-Tree Insertion Example 5

  24. B Tree Insertion (name)‏ Using alphabetical comparison of last names, we start from the root: [Shaffer, Clifford] > [Dumais, Susan] so we follow the first link. The right leaf has room, so [Shaffer, Clifford] is added and we are done. Order 4 B-Tree Insertion Example 5

  25. B Tree Insertion (name)‏ Here, we add [Platt, Jenny]. From the root, [Platt, Jenny] > [Dumais, Susan], so we go to the second leaf. Since the last name Platt is already in the tree, we add [Platt, Jenny] after [Platt, John]. Order 4 B-Tree Insertion Example 6

  26. B Tree Insertion (name)‏ Next, we try to add [Chen, Jian]. From the root, since [Chen, Jian] < [Dumais, Susan], we follow the left link to the first leaf. Since this leaf is full, we will have to perform a split. Order 4 B-Tree Insertion Example 7

  27. B Tree Insertion (name)‏ We will split the node around [Chen, Ming]. Order 4 B-Tree Insertion Example 7

  28. B Tree Insertion (name)‏ Since there is room in the root, [Chen, Ming] is added to the root. This completes the insertion. Order 4 B-Tree Insertion Example 7

  29. B Tree Insertion (name)‏ For one more insertion, we'll add [Chen, Xiao]. From the root, since the last name Chen is already in the root, we'll add [Chen, Xiao] after [Chen, Ming]. This means we will follow the middle link. Order 4 B-Tree Insertion Example 8

  30. B Tree Insertion (name)‏ Since the middle leaf already has the last name Chen, we will add [Chen, Xiao] after [Chen, Zheng] and we are done. Order 4 B-Tree Insertion Example 8

More Related