Figure 1

B+-Tree File Structure
A B+-Tree is a balanced tree.
It is a multiple-level index structure.
A node of a B+-Tree of order n contains up to (n-1) search key values, sorted
in order, and n pointers.
Node structure of a B+-Tree of order n:
P1
K1
P2
....
Pn-1 Kn-1
Pn
In a leaf node there are at least ceil((n-1)/2) key values. Key values in the leaf
nodes form a total index for the file.
In the root of the tree, there are at least 2 pointers.
In each intermediate node, there are at least ceil(n/2) pointers.
In the leaf nodes, the pointer Pi (1 <= i <= (n-1)) points to the block of the
prime data area where the record with the search key value of Ki is stored. The
pointer Pn is used to chain leaf nodes together to facilitate sequential searching
of the file in search key order.
The structure of the non-leaf nodes ( the root and the intermediate nodes) are
the same as that of the leaf nodes, except all pointers point to tree nodes.
The pointer Pi (2 <= i <= (n-1)) points to the subtree that contains
search key values less than Ki and greater than or equal to Ki-1.
The pointer P1 points to the subtree that contains search key values
less than K1.
The pointer Pn points to the subtree that contains search key values
greater than or equal to Kn-1.
40
30
10
20
50
30
40
To 10
Figure 1- A B+-Tree of Order 3
50
60
40
30
10
20
50
30
40
50
To 10
Figure 2 – Example of the Search Algorithm (for Search Key
Value of 20) – STEP 1
Red arrows define the search path.
Note that each search begins at the root of the tree and
terminates at a leaf node.
60
40
30
10
20
50
30
40
50
To 10
Figure 2 – Example of the Search Algorithm (for Search Key
Value of 20) – STEP 2
Red arrows define the search path.
Note that each search begins at the root of the tree and
terminates at a leaf node.
60
40
30
10
20
50
30
40
50
To 10
Figure 2 – Example of the Search Algorithm (for Search Key
Value of 20) – STEP 3 (Successful search)
Red arrows define the search path.
Note that each search begins at the root of the tree and
terminates at a leaf node.
60
40
30
10
20
50
30
35
40
Figure 3 – The Insertion Algorithm Demonstrated (Insert 35)
Insertion into a leaf node with available search key space.
50
60
40
30
10
20
50
30
40
50
60
New node
Figure 3 – The Insertion Algorithm Demonstrated (Insert 15)
Insertion that causes node splitting.
1. Insert the record with search key value of 15 into the prime data area.
2. Search the tree for the target leaf node.
3. If there is no space in the target leaf node, acquire a new node from the operating system.
40
20
10
15
30
30
50
40
50
60
20
Figure 3 – The Insertion Algorithm Demonstrated (Insert 15)
Insertion that causes node splitting.
4. Insert 15 into the target leaf and the overflowing key value of 20 into the new node.
5. Insert the overflowing search key value of 20 into the parent of the target node. If no space in
the parent node, proceed recursively until either such an insertion is possible, or a new root has
to be created, adding 1 to the height of the tree.
6. Adjust the pointers.
40
30
10
20
50
30
40
50
60 removed
To 10
Figure 4- The Deletion Algorithm Demonstrated (Delete 60 from the tree
of Figure 1)
Deletion from a leaf node that contains enough search key values after deletion.
1. Search for 60.
2. Remove 60 from the target leaf node.
3. Delete the record with search key value of 60 from the prime data area.
4. Adjust pointers.
40
20
10
15
30
30
50
40
50
60
20
Figure 4 – The Deletion Algorithm Demonstrated (Delete 20 from the tree of
Figure 3 after the insertion of 15 into the tree of Figure 1)
Deletion that causes combining nodes.
1. Search for 20.
2. Delete the record with search key value of 20 from the prime data area.
40
30
50
20
removed
10
15
30
40
50
60
20
Returned to O. S.
Figure 4 – The Deletion Algorithm Demonstrated (Delete 20 from the tree of
Figure 3 after the insertion of 15 into the tree of Figure 1)
Deletion that causes combining nodes.
3. If the target node becomes empty after deletion, return the target node to the operating system.
4. Remove 20 from the parent of the target leaf node.
5. Arrange the content of the parent node of the target leaf node.
6. Adjust the pointers.
30
10
15
50
30
50
60
Figure 5 – Deletion Algorithm Demonstrated (Delete 40 from the tree of
Figure 4)
The tree after this deletion is shown above. Note that two intermediate nodes are combined, and the
height of the tree is decreased by 1.
40
20
10
30
15
50
30
40
50
60
20
Figure 5 – The Deletion Algorithm Demonstrated (Delete 40 from the above
tree)
Note that the intermediate nodes cannot be combined. In this case we re-distribute the pointers. The
resulting tree is shown below.
30
20
10
15
50
30
20
30
50
60