B tree &
-
Upload
memonayounas -
Category
Automotive
-
view
30 -
download
0
Transcript of B tree &
B TREE &BASIC OPERATIONDESIGN & ANALSIS ALGORITHMS
Group #4
DELETION IN BTREE
0Deletion is similar to insertion in Btree 0Key can be deleted from any node.0Therefore, you must ensure that before/after deletion,
the B-Tree maintains its properties
0Tip: after deletion root node must have one data value
DELETION IN BTREE
0Case#1:- if x is a leaf node and x has >= keys then just delete the key from node-x
delete: “B”
keys =3=t
D G
H I E F A B C
DELETION IN BTREE
After Deletion Tip: In this case you
can directly delete node in
leaf
D G
E F H I A C
DELETION IN BTREE
CASE 2: the node x containing the target key is a leaf and x has exactly (t-1) keys , i.e, the min of keys that x should have then (a) If x has a sibling with at least t keys , then move x’s
parent key into x and move the appropriate of form x’s sibling into the open slot in parent nodes then delete the target
DELETION IN BTREE
G H K L O P R
J M DELET “L”
That node x contain target , it has min no of key is 2 (as t=3)
sibling o f x that has >=3 keys
DELETION IN BTREE
J M O
G H K L P R
DELET “L”
DELETION IN BTREE
G H K L M P R
J O
DELETION IN BTREE
G H K M P R
J O
DELETION IN BTREE
0 (b) If x’s siblings also have (t-1) keys merge x with one of its sibling by bringing down the parent as the median key , then delete the key
Q T
O P R S W X
DELET “S”
Node x contain the key node of the siblings of node x have >=t keys all have t-1=2 keys
DELETION IN BTREE
Q
O P R S T W X
DELET “S”
DELETION IN BTREE
Q
O P R S T W X
DELET “L”
DELETION IN BTREE
Q
O P R T W X
DELET “S ”
DELETION IN BTREE
Q R
O P T W X
DELETION IN BTREE
R
O P Q
T W X
DELETION IN BTREE 0CASE #3 if the node x containing the target key is as the
internal node 0 (a) it the target key’s left child has at least t keys then its target
value can be moved to the parent to replace the target key
Q U
O R R S T W X
DELET “U ”U has a subtree root then t =3 keys
DELETION IN BTREE
Q T U
O P R S W X
DELET “U”
DELETION IN BTREE
Q T
O P R S W X
DELETION IN BTREE
0 (B) if the target keys right child has at least t key then its smallest value can moved to the parent to replace the target key
I M
G M J K L O P
DELET “I”
DELETION IN BTREE
I J M
G M K L O P
DELET “I”
DELETION IN BTREE
J M
G M K L O P
DELETION IN BTREE
(C) IF the node of the target keys children have at least t keys then the children must be merged into one and the key could be removed
R U X
P Q S T V W
DELETE “U ”
Y Z
DELETION IN BTREE
0 R U X
P Q S T V W Y Z
DELET “U ”
DELETION IN BTREE
R X
P Q S T V W Y Z