Delete example 1: easy case
Delete the
search key 17 from
the B+-tree index
Delete example 1: easy case
Find the
search key 17 in
a leaf node
Delete example 1: easy case
Remove the
search key 17 and
its record pointer
Delete example 1: easy case
Check for
underflow condition:
no overflow -
done !!
(notice anything in the internal nodes ?)
Delete example 1: easy case
Note:
search keys in
internal nodes are
used to access the
(actual) index file
stored in the
leaf nodes !
Example 2: deletion solved by a transfer
Delete the
search key 7 from
the B+-tree index
(I will skip the
search step)...
Example 2: deletion solved by a transfer
After deletion, we
check for underflow:
max = 3 keys,
min occupancy: 2 keys -
underflow !!
Example 2: deletion solved by a transfer
The left sibling has
3 keys --
sibling has
a key to spare:
transfer
the last key (=5)
Example 2: deletion solved by a transfer
We must update the
search key in
the parent node !!!
(B+-tree is wrong if you omit update - next)
Example 2: deletion solved by a transfer
If key update is omitted,
the search key 5 is
in the wrong branch of the
B+-tree !!!
Example 3: deletion solved by a merge
operation
Delete the
search key 11
Example 3: deletion solved by a merge
operation
Resulting node has
< 2 search keys:
underflow
Example 3: deletion solved by a merge
operation
Sibling nodes have
no key to
spare....
Example 3: deletion solved by a merge
operation
Merge the
underflow node with
its left sibling
and
call
DeleteInternal(... parent(L))
to
delete empty node ...
Example 3: deletion solved by a merge
operation
DeleteInternal(... parent(L))
will delete
search key 5 and
its right tree pointer...
Example 3: deletion solved by a merge
operation
After deletion, we
check for underflow condition --
no underflow:
done !!!
Example 4: deletion solved by a merge
and then a transfer
Delete the
search key 11
Example 4: deletion solved by a merge
and then a transfer
Sibbling node can
not spare any keys - so we
cannot use
transfer to resolve underflow
Example 4: deletion solved by a merge
and then a transfer
As last resort, we
merge the
underflow node with its
(left) sibling
Example 4: deletion solved by a merge
and then a transfer
Merge will result in a
empty (right) node:
call
DeleteInternal( 2, 5, parent(L) )
Example 4: deletion solved by a merge
and then a transfer
After DeleteInternal( 2, 5, parent(L) ),
the resulting node
has 1 pointer
(and must have ≥ 2) --
underflow
Example 4: deletion solved by a merge
and then a transfer
The right sibling node has
1 pointer to spare:
use transfer
- which is like a tree rotation
Example 4: deletion solved by a merge
and then a transfer
Transfer will:
(1) copy 13 from parent + left most link from sibling
and
(2) replace 13 with the left most key in sibling
Example 4: deletion solved by a merge
and then a transfer
Tree is
redrawn - you can see that there
are no underflow nodes -
done !!
Example 5: how a B+-tree decrees in # levels
Delete the
search key 11
Example 5: how a B+-tree decrees in # levels
Result node is
underflow -
must use merge to
resolve underflow
Example 5: how a B+-tree decrees in # levels
After merging,
we proceed to delete the
empty node from tree
Example 5: how a B+-tree decrees in # levels
Empty node is
removed by
deleting (key, rightTreePtr) from
parent node
Example 5: how a B+-tree decrees in # levels
Resulting node is
underflow that must be
resolved with
a merge operation
Example 5: how a B+-tree decrees in # levels
Figure denotes the
movement of
keys and pointers in
merge operation -
always merged into the left node
Example 5: how a B+-tree decrees in # levels
After merging,
we must remove the
empty node from the
B+-tree
Example 5: how a B+-tree decrees in # levels
This is done by
deleting
a (key, rightTreePtr) from
parent node
Example 5: how a B+-tree decrees in # levels
Resulting (root) node
has only 1 pointer -
underflow
Example 5: how a B+-tree decrees in # levels
We simply remove a
root node that has
1 pointer and make
the child node the
new root !!
❮
❯