Docsity

B-Trees: Definition, Properties, and Algorithms for Insertion and Deletion, Slides of Data Structures and Algorithms

Partial preview of the text

Download B-Trees: Definition, Properties, and Algorithms for Insertion and Deletion and more Slides Data Structures and Algorithms in PDF only on Docsity!

Introduction

 Definition of B-trees

 Properties

 Specialization

 Examples

 2-3 trees

 Insertion of B-tree

 Remove items from B-tree

B-Trees

  • Definition

A balanced search tree in which every node has between m/2 and m children, where m>1 is a fixed integer. M is the order. The root may have as few as 2 children. This is a good structure if much of the tree is in slow memory (disk), since the height, and hence the number of accesses, can be kept small, say one or two, by picking a large m. M is the height of a tree, the maximum number of children of nodes in a B-tree.

Specialization

  • 2-3-4 tree

A B-tree of order 4, that is, internal nodes have two, three, or four children. B-tree with m=4.

• 2-3 tree

A B-tree of order 3, that is, internal nodes have two or three children.

• B*-tree

A B-tree in which nodes are kept 2/3 full by redistributing keys to fill two child nodes, then splitting them

Example of B-Trees

B+ Tree with four keys

This table shows a B+ tree. As the example illustrates this tree does not have a full index page. (We have room for one more key and pointer in the root page.) In addition, one of the data pages contains empty slots

  • The following examples illustrate each of

the insert scenarios. We begin with the

simplest scenario: inserting a record into a

leaf page that is not full. Since only the leaf

node containing 25 and 30 contains

expansion room, we're going to insert a

record with a key value of 28 into the B+

tree. The following figures shows the result

of this addition.

Add to a non-full tree

  • Add Record with Key 28

Add Record with Key 70

  • The middle key of 60 is placed in the index page between 50 and 75. The following table shows the B+ tree after the addition of 70.

Adding a record when both the leaf page and

the index page are full

  • As our last example, we're going to add a record containing a key value of 95 to our B+ tree. This record belongs in the page containing 75, 80, 85, and 90. Since this page is full we split it into two pages:
  • Left Leaf Page Right Leaf Page
  • 75 80 85 90 95

The following table illustrates the addition of the record containing 95 to the B+ tree.

Deleting Keys from a B+ tree

  • As our example, we consider the B+ tree after we added 95 as a key. As a refresher this tree is printed in the following table.
  • Delete Record with Key

Delete 25 from the B+ tree

Next, we delete the record containing 25 from the B+

tree. This record is found in the leaf node containing

25, 28, and 30. The fill factor will be 50% after the

deletion; however, 25 appears in the index page. Thus,

when we delete 25 we must replace it with 28 in the

index page.

Delete 60 from the B+ tree

  • As our last example, we're going to delete 60 from the B+ tree. This deletion is interesting for several reasons:
  1. The leaf page containing 60 (60 65) will be below the fill factor after the deletion. Thus, we must combine leaf pages.
  2. 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.
  3. Sixty appears as the only key in the root index page. Obviously, it will be removed with the deletion.

The following table shows the B+ tree after the deletion of 60. Notice that the tree contains a single index page.

Delete Record with Key 60