b tree &

24
B TRE E & BASIC OPERATION DESIGN & ANALSIS ALGORITHMS Group #4

Upload: memonayounas

Post on 21-Feb-2017

30 views

Category:

Automotive


0 download

TRANSCRIPT

Page 1: B tree &

B TREE &BASIC OPERATIONDESIGN & ANALSIS ALGORITHMS

Group #4

Page 2: B tree &

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

Page 3: B tree &

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

Page 4: B tree &

DELETION IN BTREE

After Deletion Tip: In this case you

can directly delete node in

leaf

D G

E F H I A C

Page 5: B tree &

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

Page 6: B tree &

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

Page 7: B tree &

DELETION IN BTREE

J M O

G H K L P R

DELET “L”

Page 8: B tree &

DELETION IN BTREE

G H K L M P R

J O

Page 9: B tree &

DELETION IN BTREE

G H K M P R

J O

Page 10: B tree &

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

Page 11: B tree &

DELETION IN BTREE

Q

O P R S T W X

DELET “S”

Page 12: B tree &

DELETION IN BTREE

Q

O P R S T W X

DELET “L”

Page 13: B tree &

DELETION IN BTREE

Q

O P R T W X

DELET “S ”

Page 14: B tree &

DELETION IN BTREE

Q R

O P T W X

Page 15: B tree &

DELETION IN BTREE

R

O P Q

T W X

Page 16: B tree &

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

Page 17: B tree &

DELETION IN BTREE

Q T U

O P R S W X

DELET “U”

Page 18: B tree &

DELETION IN BTREE

Q T

O P R S W X

Page 19: B tree &

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”

Page 20: B tree &

DELETION IN BTREE

I J M

G M K L O P

DELET “I”

Page 21: B tree &

DELETION IN BTREE

J M

G M K L O P

Page 22: B tree &

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

Page 23: B tree &

DELETION IN BTREE

0 R U X

P Q S T V W Y Z

DELET “U ”

Page 24: B tree &

DELETION IN BTREE

R X

P Q S T V W Y Z