# Redistribution or Merging

Only available on StudyMode
• Topic: Trees, Graph theory
• Pages : 9 (634 words )
• Published : February 27, 2013

Text Preview
N: maximum number of keys per node.
D : node from which key is to be deleted.

L : left sibling of D

R: right sibling of D

After deleting key from leaf node D, if D contains less than ceil(N/2) keys ( i.e. underflow in D), then check the following cases. Redistribution or Merging

1) Redistribution for Leaf node

i) If L or R node contains ceil(N/2) + 1 or more keys then

a) Move the rightmost key from L to D in case of left sibling.

b) Move the leftmost key from R to D in case of right sibling.

ii) Then replace the parent key of these nodes with maximum key from L ( in case of L & D) or maximum key from D ( in case of D & R).

.

After deleting 10, we have

Redistribute and change the parent key.

NOTE: A key can appear at only one ancestor D( in the leaf)

After deleting key from D, replace the key (deletion key) in the internal node by the smallest key in D.

2) Merging

This case arises If the sibling L or R node contains exactly ceil (N/2) keys, then

a) If there are keys remaining in D, Move the key or keys from D to L or R.

b) Since D node is empty, remove the pointer from parent to D.

c) Delete the key between L or R and D from the parent node.

Deleting the key from internal node

Suppose we remove a key from internal node D and after deleting if D has less than ceil(N+1/2)-1 keys then choose any one of the following cases:

Case 1 (Redistribution):- If L or R has >= ceil(N+1/2) keys then,

a. Move the parent key between D and L or R down to D.

b. Make leftmost child of R as the rightmost child of D.

Or

Make rightmost child of L as the leftmost child of D.

c. Move the leftmost child (in case of R) or rightmost child (in case of L) to become

Parent key.

Case 2 (Merging):-

If L or R contains exactly ceil(N+1/2)-1 keys then,

a) Move separating key down to D.

b) Move the keys and child pointer in D to L or R.

c) Remove the pointer to D at parent.

Case 3 :- If D is a root and D is empty, then remove D and make its children the new root.

Delete 2 from the above table.

Case of deleting key from leaf node. Merging in leaf node takes place.

Case of deleting key from internal node. Merging in internal node takes place.

Case of deleting key from internal node. Merging in internal node takes place.

Case of deleting key from internal node. Merging in internal node takes place.

Case of deleting key from internal node. Merging in internal node takes place.

Root node becomes empty. So this is the case of forming new root.

-----------------------
9

10

2 9

9

2 9

2

9

2

10

9

10

2 9

9

2

9

2

9

15

18

20 22

25

26 37

43 45

51 54

9 15

22 25

45

18 37

9

15

18

20 22

25

26 37

43 45

51 54

9 15

22 25

45

18

37

9

15

18

20 22

25

26 37

43 45

51 54

9 15

22 25

45

37

18

9

15

18...