B+ Tree
B+ Tree
B+ Tree
B - Tree
• B-Tree is m way search tree (m is odd number)
• It is a self-balanced search tree in which every node
contains multiple keys and has more than two children.
• Large degree B-trees used to represent very large
dictionaries that reside on disk.
• Smaller degree B-trees used for internal-memory
dictionaries to overcome cache-miss penalties
Properties of B-Tree
Operations on a B-Tree
• Search
• Insertion
• Deletion
Search Operation in B-Tree
Insertion Operation in B-Tree
(Same as construction)
Example Construct a B-Tree of Order 3 by inserting numbers from 1 to 10.
Constructing a B-tree : Example 2
• Suppose we start with an empty B-tree and keys arrive in the
following order:
1 12 8 2 25 5 14 28 17 7 52 16 48 68 3 26 29 53 55 45
• We want to construct a B-tree of order 5
• The Prst four items go into the root:
1 2 8 12
• To put the Pfth item in the root would violate rule (maximum m-1
nodes)
• Therefore, when 25 arrives, pick the middle key to make a new root
Constructing a B-tree (contd.)
1 2 12 25
1 2 6 12 14 25 28
Constructing a B-tree (contd.)
Adding 17 to the right leaf node would over-fill it, so we take the
middle key, promote it (to the root) and split the leaf
8 17
1 2 6 12 14 25 28
7
,52
,16
,48g
eta
dde
dtot
hel
eafno
des
8 17
1 2 6 7 12 14 16 25 28 48 52
Constructing a B-tree (contd.)
Adding68c a
usesust ospl
itt
heri
ghtmostlea
f,pr
omoti
ng48tot
he
r
oot,andadding3c ause
sustospl
itt
heleftmostl
eaf
,pr
omoti
ng3
t
other oo
t;26,29,53,55thengoint
otheleav
es
3 8 17 48
1 2 6 7 12 14 16 25 26 28 29 52 53 55 68
17
3 8 28 48
1 2 6 7 12 14 16 25 26 29 45 52 53 55 68
B-Trees 17
Removal from a B-tree
During insertion, the key always goes into a leaf. For deletion we wish to
remove from a leaf. There are three possible ways we can do this:
• 1 - If the key is already in a leaf node, and removing it doesn’t cause that
leaf node to have too few keys, then simply remove the key to be deleted.
Assuming a 5-way
B-Tree, as before... 12 29 52
2 7 9 15 22 31 43 56 69 72
Delete 52
12 29 56
52
7 9 15 22 31 43 56 69 72
12 29 56
7 9 15 22 31 43 69 72
Too few keys!
Delete 72
Type #4: Too few keys in node and
its siblings
12 29
7 9 15 22 31 43 56 69
Type #3: Enough siblings
12 29
Demote root key and
promote leaf key
7 9 15 22 31 43 56 69
Delete 22
Type #3: Enough siblings
12 31
7 9 15 29 43 56 69
Advantages of B tree