### Solving underflow with merging

• Underflow that cannot be solved by transfer

• Fact:

 If both immediate sibling nodes of an underflow (has less than 1 subtree after deletion) node have only one entry in them, you cannot use the transfer technique to resolve the underflow condition

Example:

Transfering an entry form the sibling node will cause an underflow at the sibling node itself !

• Solving underflow by merging ---- when both siblings have 2 (= minimum number) subtrees

• Technique:

• If an underflow condition occurs in a delete operation, and BOTH immediate sibling nodes have 2 subtrees, we must solve the underflow condition by:

• A 3-way merge operation using

 ``` All the subtrees and entries from the sibling node + The (1 remaining) subtree in underflow node + the parent key entry (to provide search direction !!!) ```

• The left merge operation

• Merging with your left sibling:

• What happens in a merge operation with a left sibling:

• The merge operation with a left sibling:

Explanation:

• You move the sandwiched entry from the parent node into the left sibling to:

 Provide correct search direction for the subtree in the underflow node !!!

The right child reference (in magenta color) is deleted because it reference to a node that will be removed

• In general, there will be a subtree reference (denoted red rectangle) that must be included as the right subtree of the entry from the parent node

• Notice that:

• After a merge operation, the subtree under the red reference has a different parent node !!!

Example:

We must update the parent reference of that subtree after the merge operation...

• Example:

• remove(6):

• Underflow (less than 2 subtrees):

• Perform a left merge operation:

• Result:

• The right merge operation

• Merging with your right sibling:

• What happens in a merge operation with a right sibling:

• The merge operation with a right sibling:

• Notice that:

 The subtree under the red reference has a different parent node !!! (No picture, you can refer to the one above - it is similar)

• Example:

• remove(6):

• Underflow (less than 2 subtrees) :

• Perform a right merge operation:

• Result: