Академический Документы
Профессиональный Документы
Культура Документы
Underflow conditions B+ tree Deletion Algorithm Leaf key rotations Deletion Summary Deletion Case 1: No underflow Deletion Case 2: Key borrowing (key rotation) from adjacent leaf sibling Deletion Case 3: Leaf merging Deletion Case 4: Internal key borrowing (internal key rotation) Case 5: Merging internal nodes 1
Deletion Summary
We first fix the separator issue. After that, we check if the leaf underflows. If it is the case, we always try to borrow from an adjacent sibling (first looking at adjacent right sibling, then, if not possible, adjacent left sibling). If an adjacent sibling x has some extra keys, we borrow an extra key from the sibling (min if x is a right sibling and max if it is a left one), COPY the new minimum key of the right sibling to the separating key in the parent, and fix the references DONE Else, if ALL the siblings have the minimum number of keys L/2, we need to merge the underflow leaf with an adjacent sibling (right sibling, then, if not possible, left sibling).
Let u be the leaf node with underflow. Let v be the adjacent sibling:
Move the keys in u to v. Remove the reference to u at parent [i.e., delete u] Delete the separating key between u and v from the parent.
The merge process deletes one key from the parent, so the parent may underflow need to continue the process in the worst case, we may go up to the root:
If an internal node underflows use the borrowing or merge algorithms given in slide 15, 16 and 19
Delete 20
No leaf underflow 9
Deletion in B+ Tree- Case 2a: Leaf key borrowing from Right sibling
Example: Delete 25 from the following B+ tree of order M = 3 and L = 3
Delete 25
Leaf underflow
Borrow min key 30 from right sibling
10
Deletion in B+ Tree Case 2b: Leaf key borrowing from left sibling
Example: Delete 17 from the following B+ tree of order M = 3 and L = 3
Delete 17
Leaf underflow
11
Delete 15
Leaf underflow
Cannot borrow. Merge overflow node with adjacent right sibling
12
Delete 19
Leaf underflow
13
Note: Contrast with Leaf key borrowing where the leftmost key in the right sibling is COPIED up to the parent to replace the separating key
14
Note: Contrast with Leaf key borrowing where the leftmost key in the right sibling is COPIED up to the parent to replace the separating key
15
Delete 26
Leaf underflow
Cannot borrow. Merge overflow node with adjacent right sibling
16
Deletion in B+ Tree Example of Borrowing internal key from right sibling (contd)
17
Delete 20
Leaf underflow
Cannot borrow. Merge overflow node with adjacent left sibling
18
Deletion in B+ Tree Example of Borrowing internal key from left sibling (contd)
19
Move the separating key between w and v in the parent of w and v down to w. Note that this corresponds to deleting separating key from the parent of w and v. Move the keys and child references in w to v. Remove the reference to w in the parent.
If the parent of the merged node underflows, the merging process propagates upward. In the limit, a root with one key is deleted and the height decreases by one.
20
21
Delete 34
Leaf underflow
Cannot borrow. Merge overflow node with adjacent left sibling Cannot borrow. Merge node with adjacent right sibling
22
23
underflow
Cannot borrow. Merge overflow node with adjacent left sibling
24