1 / 25

Chapter 12 B+ Trees

Chapter 12 B+ Trees. CS 157B Spring 2003 By: Miriam Sy. B+ Tree. The B+ Tree index structure is the most widely used of several index structures that maintain their efficiency despite insertion and deletion of data.

Download Presentation

Chapter 12 B+ Trees

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. Chapter 12B+ Trees CS 157B Spring 2003 By: Miriam Sy

  2. B+ Tree • The B+ Tree index structure is the most widely used of several index structures that maintain their efficiency despite insertion and deletion of data. • It takes the form of a balanced tree in which every path from the root of the tree to a leaf is of the same length.

  3. B Trees: Multi-way trees Dynamic growth Contains only data pages B+ Trees: Contains features from B Trees Contains index and data pages Dynamic growth B Trees & B+ Trees

  4. Fill Factor • B+ Trees use a “fill factor” to control the growth and the shrinkage. • 50% fill factor is the minimum for a B+ Tree. • For n=4, the following guidelines must be met:

  5. B+ Trees • B+ Tree with n=4

  6. Inserting Records • The key value determines a record’s placement in a B+ Tree • The leaf pages are maintained in sequential order AND a doubly linked list (usually not shown) ,which connects each leaf page with its sibling page(s). This doubly linked list speeds data movement as the pages grow and contract.

  7. Insertion Algorithm

  8. Insertion Algorithm cont…

  9. Insertion 1st Case: leaf page & index page NOT FULL • Original Table: • Insert 28:

  10. Insertion 2nd Case: leaf page is Full but index page is Not Full • Next, we’re going to insert a record with a key value of 70. This record should go in the leaf page with 50, 55, 60, and 65. Unfortunately, this page is already full so we need to split nodes into the following: The middle key (60) is placed in the index page between 50 and 75.

  11. B+ Tree after insertion of 70

  12. Insertion 3rd Case: leaf page & index page is FULL • For our last example, we need to add 95 This record belongs in the page containing 75, 80, 85, and 90. Unfortunately, this is full so we need to split it into two pages: • The middle key, 85, rises to the index page. Unfortunately, the index page is also full so we must split it up:

  13. B+ Tree after insertion of 95

  14. Rotation • B+ Trees can incorporate rotation to reduce the number of page splits. • A rotation occurs when a leaf page is full, but one of its siblings pages is not full. Rather than splitting the leaf page, we move a record to its sibling, adjusting indices as necessary. • The left sibling is usually checked first, then the right sibling.

  15. Rotation • For example, consider the B+ Tree before the addition of 70. As previously stated, this record belongs in the leaf node containing 50 55 60 65. Notice how this node is full but it’s left sibling is not. • Using rotation, we shift the record with the lowest key to its sibling. We must also modify the index page since this key also appears there.

  16. Rotation • This is what the new B+ Tree looks like with the rotation:

  17. Deletion Algorithm • Like the insertion algorithm, there are three scenarios we must consider when deleting a record from a B+ Tree. • First Scenario:

  18. Deletion Algorithm cont…

  19. Deletion • To refresh our memories, here’s our B+ Tree right after the insertion of 95:

  20. Deletion (1st case) • Delete record with Key 70

  21. Deletion (2nd case) • Delete 25 from the B+ Tree • Because 25 appears in the index page, when we delete 25, we must replace it with 28 in the index page.

  22. Deletion (3rd case) Deleting 60 from the B+ Tree • The leaf page containing 60 (60 65) will be below the fill factor after the deletion. Thus, we must combine leaf pages. • With recombined pages, the index page will be reduced by one key. Hence, it will also fall below the fill factor. Thus, we must combine index pages. • 60 appears as the only key in the root index page. Obviously, it will be removed with the deletion.

  23. Deletion (3rd case) • B+ Tree after deletion of 60

  24. B+ Trees in Practice • Typical Order: 100 • Typical Fill Factor: 67% • Typical Capacities: • Height 4: 133^4 = 312,900,700 records • Height 3: 133^3 = 2,352,637 records

  25. Concluding Remarks • Tree structured indexes are ideal for range-searches, also good for equality searches • B+ Tree is a dynamic structure • Insertions and deletions leave tree height balanced • High fanout means depth usually just 3 or 4 • Almost always better than maintaining a sorted file

More Related