You are on page 1of 37

B+ Tree

- Balanced Tree because every path from root to leaf is of same length.
- Leaf nodes on same level.
- B+ tree contains repeating values.
- Nonleaf nodes of B+ tree form a multilevel(sparse) index on the leaf node.
- Each nonleaf node(internal node) has between n/2 to n children. i.e., minimum n/2 and
maximum n fanouts (no. of
pointers coming out from an internal node).
- Each leaf node contains minimum (n-1)/2 and maximum (n-1) values.
- No. of pointers in a node is called fanout.
- All data should come in leaf node.
- Split if elements in a node is > n-1
- For order n B+ tree, the format of node is as follows.

Pointer1 Key Pointer2 Key Pointer3 Key Pointern-1 Key Pointern


Value1 Value2 Value3 ……………. ……………. Valuen-1
Insertion in B+ Tree

Consider the following points to form the B+ Tree.


1. Insertion is always done at leaf node. Split the node if insertion of new element results into “total elements in the node” > =
n. When the node is splitted, median value will go in the previous level’s internal node and also repeated in the leaf node.
2. If element is repeated more than two times in the tree (in leaf node + on any internal nodes, it should be removed from the
internal node immediately connecting the leaf node. i.e., any element will be repeated at the most twice in the B+ Tree. (1) in
leaf node and (2) in internal/root node which is not connecting the leaf node directly.
3. For order n tree,
- Each nonleaf node(internal node) has between n/2 to n children. i.e., minimum n/2 and maximum n fanouts (no. of
pointers coming out from an internal node).
- Each leaf node contains minimum (n-1)/2 and maximum (n-1) values.
Ex.1, for B+ tree of order n=4,
- Each internal node will have min 2 (n/2=4/2=2) and maximum 4(n=4) pointers coming out of the node.
- Each leaf node will contain min 2 [(4-1)/2=3/2=2] and max 3 [n-1=4-1] values.
Ex.2, for B+ tree of order n=3,
- Each internal node will have min 2 (n/2=3/2=2) and maximum 3(n=3) pointers coming out of the node.
- Each leaf node will contain min 1 [(3-1)/2=2/2=1] and max 2 [3-1=2] values.
Ex.3, for B+ tree of order n=5,
- Each internal node will have min 3 (n/2=5/2=3) and maximum 5(n=5) pointers coming out of the node.
- Each leaf node will contain min 2 [(5-1)/2=4/2=2] and max 4 [5-1=4] values.
E
x
a
m
p
l
e
E
x
a
m
p
l
e
E
x
a
m
p
l
e
Deletion from B+ Tree
B+ Tree Deletion Case-1 No Underflow/Underfull
B+ Tree Deletion Case-2a Leaf Key Borrowing from Right Sibling
B+ Tree Deletion Case-2a Leaf Key Borrowing from Left Sibling
B+ Tree Deletion Case-3a Right Leaf Merging
B+ Tree Deletion Case-3b Left Leaf Merging
B+ Tree Deletion Case-4a Borrowing Internal Key from Right Sibling
B+ Tree Deletion Case-4a Borrowing Internal Key from Right Sibling (Continued……..)
B+ Tree Deletion Case-4b Borrowing Internal Key from Left Sibling
B+ Tree Deletion Case-4b Borrowing Internal Key from Left Sibling (Continued……..)
B+ Tree Deletion Case-5 Merging Internal Nodes
B+ Tree Deletion Case-5 Merging Internal Nodes (Continued…………..)
Static Hashing
Static Hashing : Example
Extendable Dynamic Hashing
Extendable Dynamic
Hashing - Example
Dynamic Extendable Hashing - Explained

You might also like