Presentation is loading. Please wait.

Presentation is loading. Please wait.

CPSC-629 Analysis of Algorithms

Similar presentations


Presentation on theme: "CPSC-629 Analysis of Algorithms"— Presentation transcript:

1 CPSC-629 Analysis of Algorithms
Professor Jianer Chen Room 315C HRBB September 19, 2017

2 B+Trees A popular data structure used in database, dealing with data stored in disks. Notes #7

3 B+Trees A popular data structure used in database, dealing with data stored in disks. Support fast search Support dynamic changes Support range search Notes #7

4 B+Trees A B+tree node of order n
where ph are pointers (disk addresses) and kh are search-keys (values of the attributes in the index) pn kn k2 p1 k1 p0 p2 …… Notes #7

5 B+Trees A B+tree node of order n How big is n?
where ph are pointers (disk addresses) and kh are search-keys (values of the attributes in the index) How big is n? Basically we want each B+tree node to fit in a disk block so that a B+tree node can be read/written by a single disk I/O. Typically, n ~ pn kn k2 p1 k1 p0 p2 …… Notes #7

6 B+Tree Example order n = 3
root 100 30 120 150 180 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 Notes #7

7 A B+Tree of order n Each node has: n keys and n+1 pointers
These are fixed To keep the nodes not too empty, also for the operations to be applied efficiently: * Non-leaf: at least (n+1)/2 pointers (to children) * Leaf: at least (n+1)/2 pointers to data (plus a “sequence pointer” to the next leaf) Basically: use at least one half of the pointers Notes #7

8 Sample non-leaf order n = 3
57 81 95 To keys k < 57 To keys 57 k<81 To keys 81 k<95 To keys k  95 Notes #7

9 Sample leaf node order n = 3
From non-leaf node To next leaf in sequence 57 81 95 To record with key 57 To record with key 81 To record with key 95 Notes #7

10 Example (B+ tree of order n=3)
Full node Min. node 120 150 180 30 Non-leaf 3 5 11 30 35 Leaf Notes #7

11 B+tree rules Rule 1. All leaves are at same lowest level (balanced tree) Rule 2. Pointers in leaves point to records except for “sequence pointer” Rule 3. Number of keys/pointers in nodes: Max. # pointers Max. # keys Min. # keys Non-leaf n+1 n (n+1)/2 (n+1)/2 1 Leaf (n+1)/2 + 1 (n+1)/2 Root 2 1 Notes #7

12 B+tree rules Rule 1. All leaves are at same lowest level (balanced tree) Rule 2. Pointers in leaves point to records except for “sequence pointer” Rule 3. Number of keys/pointers in nodes: Max. # pointers Max. # keys Min. # keys Non-leaf n+1 n (n+1)/2 (n+1)/2 1 Leaf (n+1)/2 + 1 (n+1)/2 Root 2 1 could be 1 Notes #7

13 Search in a B+tree Start from the root Search in a leaf block
May not have to go to the data file Search(ptr, k); \\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Notes #7

14 Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1 A tree node
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Notes #7

15 Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1 A tree node
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node root 100 30 120 150 180 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 Notes #7

16 Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1 A tree node
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Search(*prt, 130) root 100 30 120 150 180 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 Notes #7

17 Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1 A tree node
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Search(*prt, 130) root 100 30 120 150 180 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 Notes #7

18 Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1 A tree node
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Search(*prt, 130) root 100 100  130 30 120 150 180 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 Notes #7

19 Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1 A tree node
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Search(*prt, 130) root 100 100  130 30 120 150 180 120  130 <150 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 Notes #7

20 Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1 A tree node
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Search(*prt, 130) root 100 100  130 30 120 150 180 120  130 <150 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 130 =130 return Notes #7

21 Range Search in B+tree To research all records whose key values are between k1 and k2: Notes #7

22 Range Search in B+tree To research all records whose key values are between k1 and k2: Range-Search(ptr, k1, k2) Call Search(ptr, k1); Follow the sequence pointers until the search key value is larger than k2. Notes #7

23 Range Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Range Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Range-Search(ptr, k1, k2) Call Search(ptr, k1); Follow the sequence pointers until the search key value is larger than k2. root 100 30 120 150 180 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 Notes #7

24 Range Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Range Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Range-Search(ptr, k1, k2) Call Search(ptr, k1); Follow the sequence pointers until the search key value is larger than k2. Range-Search(*prt, 50, 125) root 100 30 120 150 180 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 Notes #7

25 Range Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Range Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Range-Search(ptr, k1, k2) Call Search(ptr, k1); Follow the sequence pointers until the search key value is larger than k2. Range-Search(*prt, 50, 125) Search(*prt, 50) root 100 30 120 150 180 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 Notes #7

26 Range Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Range Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Range-Search(ptr, k1, k2) Call Search(ptr, k1); Follow the sequence pointers until the search key value is larger than k2. Range-Search(*prt, 50, 125) Search(*prt, 50) root 100 50 < 100 30 120 150 180 30  50 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 Notes #7

27 Range Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Range Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Range-Search(ptr, k1, k2) Call Search(ptr, k1); Follow the sequence pointers until the search key value is larger than k2. Range-Search(*prt, 50, 125) Search(*prt, 50) root 100 50 < 100 30 120 150 180 30  50 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 35 < 50 100  125 110  125 135 > 125 Not Return return return STOP 101  125 120  125 return return Notes #7

28 Insert into B+tree Notes #7

29 Insert into B+tree Basic idea:
Find the leaf L where the record r should be inserted; If L has further room, then insert r into L, and return; If L is full, spilt L plus r into two leaves (each is about half full): this causes an additional child for the parent P of L, thus we need to add a child to P; If P is already full, then we have to split P and add an additional child to P’s parent … (recursively) Notes #7

30 Insert into B+tree Simple case (space available for new child)
Leaf overflow Non-leaf overflow New root Notes #7

31 Insert into B+tree Simple case (space available for new child)
Leaf overflow Non-leaf overflow New root Notes #7

32 I. Simple case: Insert key 32
order n=3 100 30 40 3 5 11 30 31 Notes #7

33 I. Simple case: Insert key 32
order n=3 Insert(prt, 32) 100 30 40 3 5 11 30 31 Notes #7

34 I. Simple case: Insert key 32
order n=3 Insert(prt, 32) 100 32 < 100 30 40 30  32 <40 3 5 11 30 31 Notes #7

35 I. Simple case: Insert key 32
order n=3 Insert(prt, 32) 100 32 < 100 30 40 30  32 <40 3 5 11 30 31 room for 32 Notes #7

36 I. Simple case: Insert key 32
order n=3 Insert(prt, 32) 100 32 < 100 30 40 30  32 <40 3 5 11 30 31 32 Notes #7

37 Insert into B+tree Simple case (space available for new child)
Leaf overflow Non-leaf overflow New root Idea: when there is no space for a new child (all pointers are in use), split the node into two nodes, with both at least half full. Notes #7

38 Complication: node overflow
Notes #7

39 Complication: Leaf overflow
Notes #7

40 Complication: Leaf overflow
p k p’ p1 k1 … p k p k … … pn kn p* 𝑛+1 /2 𝑛+1 /2 𝑛+1 /2 +1 𝑛+1 /2 +1 pn+1 kn+1 Notes #7

41 Complication: Leaf overflow
p k k p’ p1 k1 … p k p** p k … pn kn pn+1 kn p* 𝑛+1 /2 𝑛+1 /2 𝑛+1 /2 +1 𝑛+1 /2 +1 p k p’ p1 k1 … p k p k … … pn kn p* 𝑛+1 /2 𝑛+1 /2 𝑛+1 /2 +1 𝑛+1 /2 +1 pn+1 kn+1 Notes #7

42 Complication: Leaf overflow
p k k p’ p1 k1 … p k p** p k … pn kn pn+1 kn p* 𝑛+1 /2 𝑛+1 /2 𝑛+1 /2 +1 𝑛+1 /2 +1 p k p’ p1 k1 … p k p k … … pn kn p* 𝑛+1 /2 𝑛+1 /2 𝑛+1 /2 +1 𝑛+1 /2 +1 pn+1 kn+1 Notes #7

43 Complication: Leaf overflow
p k k p’ q p1 k1 … p k p** p k … pn kn pn+1 kn p* 𝑛+1 /2 𝑛+1 /2 𝑛+1 /2 +1 𝑛+1 /2 +1 p k p’ p1 k1 … p k p k … … pn kn p* 𝑛+1 /2 𝑛+1 /2 𝑛+1 /2 +1 𝑛+1 /2 +1 pn+1 kn+1 Notes #7

44 Complication: Leaf overflow
p k k p’ ? q What is the key here? p1 k1 … p k p** p k … pn kn pn+1 kn p* 𝑛+1 /2 𝑛+1 /2 𝑛+1 /2 +1 𝑛+1 /2 +1 p k p’ p1 k1 … p k p k … … pn kn p* 𝑛+1 /2 𝑛+1 /2 𝑛+1 /2 +1 𝑛+1 /2 +1 pn+1 kn+1 Notes #7

45 Complication: Leaf overflow
p k k p’ ? q What is the key here? p1 k1 … p k p** p k … pn kn pn+1 kn p* 𝑛+1 /2 𝑛+1 /2 𝑛+1 /2 +1 𝑛+1 /2 +1 p k p’ p1 k1 … p k p k … … pn kn p* 𝑛+1 /2 𝑛+1 /2 𝑛+1 /2 +1 𝑛+1 /2 +1 pn+1 kn+1 Notes #7

46 Complication: Leaf overflow
p k k p’ q 𝑛+1 /2 +1 p1 k1 … p k p** p k … pn kn pn+1 kn p* 𝑛+1 /2 𝑛+1 /2 𝑛+1 /2 +1 𝑛+1 /2 +1 p k p’ p1 k1 … p k p k … … pn kn p* 𝑛+1 /2 𝑛+1 /2 𝑛+1 /2 +1 𝑛+1 /2 +1 pn+1 kn+1 Notes #7

47 Leaf overflow: Insert key 7 (order n = 3)
100 30 3 5 11 30 31 Notes #7

48 Leaf overflow: Insert key 7 (order n = 3)
100 30 7 3 5 11 30 31 Notes #7

49 Leaf overflow: Insert key 7 (order n = 3)
100 30 3 5 7 11 30 31 Notes #7

50 Leaf overflow: Insert key 7 (order n = 3)
100 30 3 5 7 11 30 31 3 5 11 7 Notes #7

51 Leaf overflow: Insert key 7 (order n = 3)
100 30 3 5 7 11 30 31 3 5 11 7 Notes #7

52 Leaf overflow: Insert key 7 (order n = 3)
100 30 3 5 7 11 30 31 3 5 11 7 Notes #7

53 Leaf overflow: Insert key 7 (order n = 3)
100 30 3 5 7 11 30 31 3 5 11 7 Notes #7

54 Leaf overflow: Insert key 7 (order n = 3)
100 7 30 3 5 7 11 30 31 3 5 11 7 Notes #7

55 Complication: nonleaf overflow
Notes #7

56 Complication: nonleaf overflow
p k’ p’ kn+1 pn+2 p1 k1 … p k p k p k … pn kn pn+1 (𝑛+1)/2 (𝑛+1)/2 -1 (𝑛+1)/2 +1 (𝑛+1)/2 +1 Notes #7

57 Complication: nonleaf overflow
p k’ p’ k q (𝑛+1)/2 p1 k1 p2 k2 … p k p p k … pn kn pn+1 kn+1 pn+2 (𝑛+1)/2 -1 (𝑛+1)/2 -1 (𝑛+1)/2 (𝑛+1)/2 +1 (𝑛+1)/2 +1 p k’ p’ kn+1 pn+2 p1 k1 … p k p k p k … pn kn pn+1 (𝑛+1)/2 (𝑛+1)/2 -1 (𝑛+1)/2 +1 (𝑛+1)/2 +1 Notes #7

58 Complication: nonleaf overflow
p k’ p’ k q (𝑛+1)/2 p1 k1 p2 k2 … p k p p k … pn kn pn+1 kn+1 pn+2 (𝑛+1)/2 -1 (𝑛+1)/2 -1 (𝑛+1)/2 (𝑛+1)/2 +1 (𝑛+1)/2 +1 p k’ p’ kn+1 pn+2 p1 k1 … p k p k p k … pn kn pn+1 (𝑛+1)/2 (𝑛+1)/2 -1 (𝑛+1)/2 +1 (𝑛+1)/2 +1 Notes #7

59 Complication: nonleaf overflow
p k’ p’ k q (𝑛+1)/2 p1 k1 p2 k2 … p k p p k … pn kn pn+1 kn+1 pn+2 (𝑛+1)/2 -1 (𝑛+1)/2 -1 (𝑛+1)/2 (𝑛+1)/2 +1 (𝑛+1)/2 +1 p k’ p’ kn+1 pn+2 p1 k1 … p k p k p k … pn kn pn+1 (𝑛+1)/2 (𝑛+1)/2 -1 (𝑛+1)/2 +1 (𝑛+1)/2 +1 Notes #7

60 Complication: nonleaf overflow
p k’ p’ k ? q (𝑛+1)/2 What is the key here? p1 k1 p2 k2 … p k p p k … pn kn pn+1 kn+1 pn+2 (𝑛+1)/2 -1 (𝑛+1)/2 -1 (𝑛+1)/2 (𝑛+1)/2 +1 (𝑛+1)/2 +1 p k’ p’ kn+1 pn+2 p1 k1 … p k p k p k … pn kn pn+1 (𝑛+1)/2 (𝑛+1)/2 -1 (𝑛+1)/2 +1 (𝑛+1)/2 +1 Notes #7

61 Complication: nonleaf overflow
p k’ p’ k ? q (𝑛+1)/2 What is the key here? p1 k1 p2 k2 … p k p p k … pn kn pn+1 kn+1 pn+2 (𝑛+1)/2 -1 (𝑛+1)/2 -1 (𝑛+1)/2 (𝑛+1)/2 +1 (𝑛+1)/2 +1 p k’ p’ not used kn+1 pn+2 p1 k1 … p k p k p k … pn kn pn+1 (𝑛+1)/2 (𝑛+1)/2 -1 (𝑛+1)/2 +1 (𝑛+1)/2 +1 Notes #7

62 Complication: nonleaf overflow
p k’ p’ k k q (𝑛+1)/2 (𝑛+1)/2 p1 k1 p2 k2 … p k p p k … pn kn pn+1 kn+1 pn+2 (𝑛+1)/2 -1 (𝑛+1)/2 -1 (𝑛+1)/2 (𝑛+1)/2 +1 (𝑛+1)/2 +1 p k’ p’ kn+1 pn+2 p1 k1 … p k p k p k … pn kn pn+1 (𝑛+1)/2 (𝑛+1)/2 -1 (𝑛+1)/2 +1 (𝑛+1)/2 +1 Notes #7

63 Nonleaf overflow: Insert key 160 (order n = 3)
100 120 150 180 160 150 156 179 180 210 Notes #7

64 Nonleaf overflow: Insert key 160 (order n = 3)
100 120 150 180 150 156 160 179 180 210 150 156 179 160 Notes #7

65 Nonleaf overflow: Insert key 160 (order n = 3)
100 120 150 180 150 156 160 179 180 210 150 156 179 160 Notes #7

66 Nonleaf overflow: Insert key 160 (order n = 3)
100 120 150 180 160 150 156 160 179 180 210 150 156 179 160 Notes #7

67 Nonleaf overflow: Insert key 160 (order n = 3)
100 120 150 180 no room! 160 150 156 160 179 180 210 150 156 179 160 Notes #7

68 Nonleaf overflow: Insert key 160 (order n = 3)
120 150 180 160 100 120 150 180 160 150 156 160 179 180 210 150 156 179 160 Notes #7

69 Nonleaf overflow: Insert key 160 (order n = 3)
120 150 180 160 100 120 150 180 160 150 156 160 179 180 210 150 156 179 160 Notes #7

70 Nonleaf overflow: Insert key 160 (order n = 3)
120 150 180 160 100 160 120 150 180 160 150 156 160 179 180 210 150 156 179 160 Notes #7

71 Nonleaf overflow: Insert key 160 (order n = 3)
100 160 120 150 180 150 156 160 179 180 210 Notes #7

72 Insert into B+tree Simple case (space available for new child)
Leaf overflow Non-leaf overflow New root Notes #7

73 Insert into B+tree Simple case (space available for new child)
Leaf overflow Non-leaf overflow New root Notes #7

74 New root: Insert key 45 (order n = 3)
Notes #7

75 New root: Insert key 45 (order n = 3)
10 20 30 45 1 2 3 10 12 20 25 30 32 40 Notes #7

76 New root: Insert key 45 (order n = 3)
10 20 30 1 2 3 10 12 20 25 30 32 40 45 30 32 40 45 Notes #7

77 New root: Insert key 45 (order n = 3)
10 20 30 no room 1 2 3 10 12 20 25 30 32 40 45 30 32 40 45 Notes #7

78 New root: Insert key 45 (order n = 3)
10 20 30 10 20 40 40 30 1 2 3 10 12 20 25 30 32 40 45 30 32 40 45 Notes #7

79 New root: Insert key 45 (order n = 3)
30 10 20 30 10 20 40 40 1 2 3 10 12 20 25 30 32 40 45 30 32 40 45 Notes #7

80 New root: Insert key 45 (order n = 3)
30 10 20 40 1 2 3 10 12 20 25 30 32 40 45 Notes #7

81 Pseudo Code for Insertion in B+tree
Insert(pt, (p, k), (p', k')); \\ technically, the smallest key kmin in pt is also returned \\ (p, k) is a pointer-key pair to be inserted into the subtree rooted at pt; p' is a new sibling \\ of pt, if created, and k' is the smallest key value in p' ; Case 1. pt = (p1, k1, ..., pi, ki, --, pn+1) is a leaf \\ pn+1 is the sequence pointer IF (i < n) THEN insert (p, k) into pt; return(p' = Null, k' = 0); ELSE re-arrange (p1, k1), ..., (pn, kn), and (p, k) into (ρ1, κ1, ..., ρn+1, κn+1); create a new leaf p''; put (ρr+1, κr+1, …, ρn+1, κn+1, --, pn+1) in p''; \\ r = (n+1)/2 put (ρ1, κ1, ..., ρr, κr, --, p'') in pt; \\ pn+1 and p'' are sequence pointers in p'' and pt. IF pt is the root THEN create a new root with children pt and p'' (and key κr+1) ELSE return(p' = p'', k' = κr+1); Case 2. pt is not a leaf find a key ki in pt such that ki-1 ≤ k < ki; Insert(pi , (k, p), (k", p")); IF (p" = Null) THEN return(k' = 0, p' = Null); ELSE IF there is room in pt, THEN insert (k", p") into pt; return(k' = 0, p' = Null); ELSE re-arrange the content in pt and (k", p") into (ρ1, κ1, ..., ρn+1, κn+1, ρn+2); create a new node p''; put (ρr+1, κr+1, …, ρn+1, κn+1, ρn+2, -- ) in p''; \\ r = (n+1)/2 leave (ρ1, κ1, ..., ρr-1, κr-1, ρr , -- ) in pt; IF pt is the root THEN create a new root with children pt and p'' (and key κr) ELSE return(p' = p'', k' = κr ). Notes #7

82 Pseudo Code for Insertion in B+tree
insert in a leaf Insert(pt, (p, k), (p', k')); \\ technically, the smallest key kmin in pt is also returned \\ (p, k) is a pointer-key pair to be inserted into the subtree rooted at pt; p' is a new sibling \\ of pt, if created, and k' is the smallest key value in p' ; Case 1. pt = (p1, k1, ..., pi, ki, --, pn+1) is a leaf \\ pn+1 is the sequence pointer IF (i < n) THEN insert (p, k) into pt; return(p' = Null, k' = 0); ELSE re-arrange (p1, k1), ..., (pn, kn), and (p, k) into (ρ1, κ1, ..., ρn+1, κn+1); create a new leaf p''; put (ρr+1, κr+1, …, ρn+1, κn+1, --, pn+1) in p''; \\ r = (n+1)/2 put (ρ1, κ1, ..., ρr, κr, --, p'') in pt; \\ pn+1 and p'' are sequence pointers in p'' and pt. IF pt is the root THEN create a new root with children pt and p'' (and key κr+1) ELSE return(p' = p'', k' = κr+1); Case 2. pt is not a leaf find a key ki in pt such that ki-1 ≤ k < ki; Insert(pi , (k, p), (k", p")); IF (p" = Null) THEN return(k' = 0, p' = Null); ELSE IF there is room in pt, THEN insert (k", p") into pt; return(k' = 0, p' = Null); ELSE re-arrange the content in pt and (k", p") into (ρ1, κ1, ..., ρn+1, κn+1, ρn+2); create a new node p''; put (ρr+1, κr+1, …, ρn+1, κn+1, ρn+2, -- ) in p''; \\ r = (n+1)/2 leave (ρ1, κ1, ..., ρr-1, κr-1, ρr , -- ) in pt; IF pt is the root THEN create a new root with children pt and p'' (and key κr) ELSE return(p' = p'', k' = κr ). Notes #7

83 Pseudo Code for Insertion in B+tree
insert in a leaf Insert(pt, (p, k), (p', k')); \\ technically, the smallest key kmin in pt is also returned \\ (p, k) is a pointer-key pair to be inserted into the subtree rooted at pt; p' is a new sibling \\ of pt, if created, and k' is the smallest key value in p' ; Case 1. pt = (p1, k1, ..., pi, ki, --, pn+1) is a leaf \\ pn+1 is the sequence pointer IF (i < n) THEN insert (p, k) into pt; return(p' = Null, k' = 0); ELSE re-arrange (p1, k1), ..., (pn, kn), and (p, k) into (ρ1, κ1, ..., ρn+1, κn+1); create a new leaf p''; put (ρr+1, κr+1, …, ρn+1, κn+1, --, pn+1) in p''; \\ r = (n+1)/2 put (ρ1, κ1, ..., ρr, κr, --, p'') in pt; \\ pn+1 and p'' are sequence pointers in p'' and pt. IF pt is the root THEN create a new root with children pt and p'' (and key κr+1) ELSE return(p' = p'', k' = κr+1); Case 2. pt is not a leaf find a key ki in pt such that ki-1 ≤ k < ki; Insert(pi , (k, p), (k", p")); IF (p" = Null) THEN return(k' = 0, p' = Null); ELSE IF there is room in pt, THEN insert (k", p") into pt; return(k' = 0, p' = Null); ELSE re-arrange the content in pt and (k", p") into (ρ1, κ1, ..., ρn+1, κn+1, ρn+2); create a new node p''; put (ρr+1, κr+1, …, ρn+1, κn+1, ρn+2, -- ) in p''; \\ r = (n+1)/2 leave (ρ1, κ1, ..., ρr-1, κr-1, ρr , -- ) in pt; IF pt is the root THEN create a new root with children pt and p'' (and key κr) ELSE return(p' = p'', k' = κr ). no overflow Notes #7

84 Pseudo Code for Insertion in B+tree
insert in a leaf Insert(pt, (p, k), (p', k')); \\ technically, the smallest key kmin in pt is also returned \\ (p, k) is a pointer-key pair to be inserted into the subtree rooted at pt; p' is a new sibling \\ of pt, if created, and k' is the smallest key value in p' ; Case 1. pt = (p1, k1, ..., pi, ki, --, pn+1) is a leaf \\ pn+1 is the sequence pointer IF (i < n) THEN insert (p, k) into pt; return(p' = Null, k' = 0); ELSE re-arrange (p1, k1), ..., (pn, kn), and (p, k) into (ρ1, κ1, ..., ρn+1, κn+1); create a new leaf p''; put (ρr+1, κr+1, …, ρn+1, κn+1, --, pn+1) in p''; \\ r = (n+1)/2 put (ρ1, κ1, ..., ρr, κr, --, p'') in pt; \\ pn+1 and p'' are sequence pointers in p'' and pt. IF pt is the root THEN create a new root with children pt and p'' (and key κr+1) ELSE return(p' = p'', k' = κr+1); Case 2. pt is not a leaf find a key ki in pt such that ki-1 ≤ k < ki; Insert(pi , (k, p), (k", p")); IF (p" = Null) THEN return(k' = 0, p' = Null); ELSE IF there is room in pt, THEN insert (k", p") into pt; return(k' = 0, p' = Null); ELSE re-arrange the content in pt and (k", p") into (ρ1, κ1, ..., ρn+1, κn+1, ρn+2); create a new node p''; put (ρr+1, κr+1, …, ρn+1, κn+1, ρn+2, -- ) in p''; \\ r = (n+1)/2 leave (ρ1, κ1, ..., ρr-1, κr-1, ρr , -- ) in pt; IF pt is the root THEN create a new root with children pt and p'' (and key κr) ELSE return(p' = p'', k' = κr ). no overflow with overflow Notes #7

85 Pseudo Code for Insertion in B+tree
insert in a leaf Insert(pt, (p, k), (p', k')); \\ technically, the smallest key kmin in pt is also returned \\ (p, k) is a pointer-key pair to be inserted into the subtree rooted at pt; p' is a new sibling \\ of pt, if created, and k' is the smallest key value in p' ; Case 1. pt = (p1, k1, ..., pi, ki, --, pn+1) is a leaf \\ pn+1 is the sequence pointer IF (i < n) THEN insert (p, k) into pt; return(p' = Null, k' = 0); ELSE re-arrange (p1, k1), ..., (pn, kn), and (p, k) into (ρ1, κ1, ..., ρn+1, κn+1); create a new leaf p''; put (ρr+1, κr+1, …, ρn+1, κn+1, --, pn+1) in p''; \\ r = (n+1)/2 put (ρ1, κ1, ..., ρr, κr, --, p'') in pt; \\ pn+1 and p'' are sequence pointers in p'' and pt. IF pt is the root THEN create a new root with children pt and p'' (and key κr+1) ELSE return(p' = p'', k' = κr+1); Case 2. pt is not a leaf find a key ki in pt such that ki-1 ≤ k < ki; Insert(pi , (k, p), (k", p")); IF (p" = Null) THEN return(k' = 0, p' = Null); ELSE IF there is room in pt, THEN insert (k", p") into pt; return(k' = 0, p' = Null); ELSE re-arrange the content in pt and (k", p") into (ρ1, κ1, ..., ρn+1, κn+1, ρn+2); create a new node p''; put (ρr+1, κr+1, …, ρn+1, κn+1, ρn+2, -- ) in p''; \\ r = (n+1)/2 leave (ρ1, κ1, ..., ρr-1, κr-1, ρr , -- ) in pt; IF pt is the root THEN create a new root with children pt and p'' (and key κr) ELSE return(p' = p'', k' = κr ). no overflow new child to parent with overflow Notes #7

86 Pseudo Code for Insertion in B+tree
Insert(pt, (p, k), (p', k')); \\ technically, the smallest key kmin in pt is also returned \\ (p, k) is a pointer-key pair to be inserted into the subtree rooted at pt; p' is a new sibling \\ of pt, if created, and k' is the smallest key value in p' ; Case 1. pt = (p1, k1, ..., pi, ki, --, pn+1) is a leaf \\ pn+1 is the sequence pointer IF (i < n) THEN insert (p, k) into pt; return(p' = Null, k' = 0); ELSE re-arrange (p1, k1), ..., (pn, kn), and (p, k) into (ρ1, κ1, ..., ρn+1, κn+1); create a new leaf p''; put (ρr+1, κr+1, …, ρn+1, κn+1, --, pn+1) in p''; \\ r = (n+1)/2 put (ρ1, κ1, ..., ρr, κr, --, p'') in pt; \\ pn+1 and p'' are sequence pointers in p'' and pt. IF pt is the root THEN create a new root with children pt and p'' (and key κr+1) ELSE return(p' = p'', k' = κr+1); Case 2. pt is not a leaf find a key ki in pt such that ki-1 ≤ k < ki; Insert(pi , (k, p), (k", p")); IF (p" = Null) THEN return(k' = 0, p' = Null); ELSE IF there is room in pt, THEN insert (k", p") into pt; return(k' = 0, p' = Null); ELSE re-arrange the content in pt and (k", p") into (ρ1, κ1, ..., ρn+1, κn+1, ρn+2); create a new node p''; put (ρr+1, κr+1, …, ρn+1, κn+1, ρn+2, -- ) in p''; \\ r = (n+1)/2 leave (ρ1, κ1, ..., ρr-1, κr-1, ρr , -- ) in pt; IF pt is the root THEN create a new root with children pt and p'' (and key κr) ELSE return(p' = p'', k' = κr ). insert in a nonleaf Notes #7

87 Pseudo Code for Insertion in B+tree
Insert(pt, (p, k), (p', k')); \\ technically, the smallest key kmin in pt is also returned \\ (p, k) is a pointer-key pair to be inserted into the subtree rooted at pt; p' is a new sibling \\ of pt, if created, and k' is the smallest key value in p' ; Case 1. pt = (p1, k1, ..., pi, ki, --, pn+1) is a leaf \\ pn+1 is the sequence pointer IF (i < n) THEN insert (p, k) into pt; return(p' = Null, k' = 0); ELSE re-arrange (p1, k1), ..., (pn, kn), and (p, k) into (ρ1, κ1, ..., ρn+1, κn+1); create a new leaf p''; put (ρr+1, κr+1, …, ρn+1, κn+1, --, pn+1) in p''; \\ r = (n+1)/2 put (ρ1, κ1, ..., ρr, κr, --, p'') in pt; \\ pn+1 and p'' are sequence pointers in p'' and pt. IF pt is the root THEN create a new root with children pt and p'' (and key κr+1) ELSE return(p' = p'', k' = κr+1); Case 2. pt is not a leaf find a key ki in pt such that ki-1 ≤ k < ki; Insert(pi , (k, p), (k", p")); IF (p" = Null) THEN return(k' = 0, p' = Null); ELSE IF there is room in pt, THEN insert (k", p") into pt; return(k' = 0, p' = Null); ELSE re-arrange the content in pt and (k", p") into (ρ1, κ1, ..., ρn+1, κn+1, ρn+2); create a new node p''; put (ρr+1, κr+1, …, ρn+1, κn+1, ρn+2, -- ) in p''; \\ r = (n+1)/2 leave (ρ1, κ1, ..., ρr-1, κr-1, ρr , -- ) in pt; IF pt is the root THEN create a new root with children pt and p'' (and key κr) ELSE return(p' = p'', k' = κr ). insert in a nonleaf recursion Notes #7

88 Pseudo Code for Insertion in B+tree
Insert(pt, (p, k), (p', k')); \\ technically, the smallest key kmin in pt is also returned \\ (p, k) is a pointer-key pair to be inserted into the subtree rooted at pt; p' is a new sibling \\ of pt, if created, and k' is the smallest key value in p' ; Case 1. pt = (p1, k1, ..., pi, ki, --, pn+1) is a leaf \\ pn+1 is the sequence pointer IF (i < n) THEN insert (p, k) into pt; return(p' = Null, k' = 0); ELSE re-arrange (p1, k1), ..., (pn, kn), and (p, k) into (ρ1, κ1, ..., ρn+1, κn+1); create a new leaf p''; put (ρr+1, κr+1, …, ρn+1, κn+1, --, pn+1) in p''; \\ r = (n+1)/2 put (ρ1, κ1, ..., ρr, κr, --, p'') in pt; \\ pn+1 and p'' are sequence pointers in p'' and pt. IF pt is the root THEN create a new root with children pt and p'' (and key κr+1) ELSE return(p' = p'', k' = κr+1); Case 2. pt is not a leaf find a key ki in pt such that ki-1 ≤ k < ki; Insert(pi , (k, p), (k", p")); IF (p" = Null) THEN return(k' = 0, p' = Null); ELSE IF there is room in pt, THEN insert (k", p") into pt; return(k' = 0, p' = Null); ELSE re-arrange the content in pt and (k", p") into (ρ1, κ1, ..., ρn+1, κn+1, ρn+2); create a new node p''; put (ρr+1, κr+1, …, ρn+1, κn+1, ρn+2, -- ) in p''; \\ r = (n+1)/2 leave (ρ1, κ1, ..., ρr-1, κr-1, ρr , -- ) in pt; IF pt is the root THEN create a new root with children pt and p'' (and key κr) ELSE return(p' = p'', k' = κr ). insert in a nonleaf recursion no overflow Notes #7

89 Pseudo Code for Insertion in B+tree
Insert(pt, (p, k), (p', k')); \\ technically, the smallest key kmin in pt is also returned \\ (p, k) is a pointer-key pair to be inserted into the subtree rooted at pt; p' is a new sibling \\ of pt, if created, and k' is the smallest key value in p' ; Case 1. pt = (p1, k1, ..., pi, ki, --, pn+1) is a leaf \\ pn+1 is the sequence pointer IF (i < n) THEN insert (p, k) into pt; return(p' = Null, k' = 0); ELSE re-arrange (p1, k1), ..., (pn, kn), and (p, k) into (ρ1, κ1, ..., ρn+1, κn+1); create a new leaf p''; put (ρr+1, κr+1, …, ρn+1, κn+1, --, pn+1) in p''; \\ r = (n+1)/2 put (ρ1, κ1, ..., ρr, κr, --, p'') in pt; \\ pn+1 and p'' are sequence pointers in p'' and pt. IF pt is the root THEN create a new root with children pt and p'' (and key κr+1) ELSE return(p' = p'', k' = κr+1); Case 2. pt is not a leaf find a key ki in pt such that ki-1 ≤ k < ki; Insert(pi , (k, p), (k", p")); IF (p" = Null) THEN return(k' = 0, p' = Null); ELSE IF there is room in pt, THEN insert (k", p") into pt; return(k' = 0, p' = Null); ELSE re-arrange the content in pt and (k", p") into (ρ1, κ1, ..., ρn+1, κn+1, ρn+2); create a new node p''; put (ρr+1, κr+1, …, ρn+1, κn+1, ρn+2, -- ) in p''; \\ r = (n+1)/2 leave (ρ1, κ1, ..., ρr-1, κr-1, ρr , -- ) in pt; IF pt is the root THEN create a new root with children pt and p'' (and key κr) ELSE return(p' = p'', k' = κr ). insert in a nonleaf recursion no overflow no overflow Notes #7

90 Pseudo Code for Insertion in B+tree
Insert(pt, (p, k), (p', k')); \\ technically, the smallest key kmin in pt is also returned \\ (p, k) is a pointer-key pair to be inserted into the subtree rooted at pt; p' is a new sibling \\ of pt, if created, and k' is the smallest key value in p' ; Case 1. pt = (p1, k1, ..., pi, ki, --, pn+1) is a leaf \\ pn+1 is the sequence pointer IF (i < n) THEN insert (p, k) into pt; return(p' = Null, k' = 0); ELSE re-arrange (p1, k1), ..., (pn, kn), and (p, k) into (ρ1, κ1, ..., ρn+1, κn+1); create a new leaf p''; put (ρr+1, κr+1, …, ρn+1, κn+1, --, pn+1) in p''; \\ r = (n+1)/2 put (ρ1, κ1, ..., ρr, κr, --, p'') in pt; \\ pn+1 and p'' are sequence pointers in p'' and pt. IF pt is the root THEN create a new root with children pt and p'' (and key κr+1) ELSE return(p' = p'', k' = κr+1); Case 2. pt is not a leaf find a key ki in pt such that ki-1 ≤ k < ki; Insert(pi , (k, p), (k", p")); IF (p" = Null) THEN return(k' = 0, p' = Null); ELSE IF there is room in pt, THEN insert (k", p") into pt; return(k' = 0, p' = Null); ELSE re-arrange the content in pt and (k", p") into (ρ1, κ1, ..., ρn+1, κn+1, ρn+2); create a new node p''; put (ρr+1, κr+1, …, ρn+1, κn+1, ρn+2, -- ) in p''; \\ r = (n+1)/2 leave (ρ1, κ1, ..., ρr-1, κr-1, ρr , -- ) in pt; IF pt is the root THEN create a new root with children pt and p'' (and key κr) ELSE return(p' = p'', k' = κr ). insert in a nonleaf recursion no overflow with overflow no overflow Notes #7

91 Pseudo Code for Insertion in B+tree
Insert(pt, (p, k), (p', k')); \\ technically, the smallest key kmin in pt is also returned \\ (p, k) is a pointer-key pair to be inserted into the subtree rooted at pt; p' is a new sibling \\ of pt, if created, and k' is the smallest key value in p' ; Case 1. pt = (p1, k1, ..., pi, ki, --, pn+1) is a leaf \\ pn+1 is the sequence pointer IF (i < n) THEN insert (p, k) into pt; return(p' = Null, k' = 0); ELSE re-arrange (p1, k1), ..., (pn, kn), and (p, k) into (ρ1, κ1, ..., ρn+1, κn+1); create a new leaf p''; put (ρr+1, κr+1, …, ρn+1, κn+1, --, pn+1) in p''; \\ r = (n+1)/2 put (ρ1, κ1, ..., ρr, κr, --, p'') in pt; \\ pn+1 and p'' are sequence pointers in p'' and pt. IF pt is the root THEN create a new root with children pt and p'' (and key κr+1) ELSE return(p' = p'', k' = κr+1); Case 2. pt is not a leaf find a key ki in pt such that ki-1 ≤ k < ki; Insert(pi , (k, p), (k", p")); IF (p" = Null) THEN return(k' = 0, p' = Null); ELSE IF there is room in pt, THEN insert (k", p") into pt; return(k' = 0, p' = Null); ELSE re-arrange the content in pt and (k", p") into (ρ1, κ1, ..., ρn+1, κn+1, ρn+2); create a new node p''; put (ρr+1, κr+1, …, ρn+1, κn+1, ρn+2, -- ) in p''; \\ r = (n+1)/2 leave (ρ1, κ1, ..., ρr-1, κr-1, ρr , -- ) in pt; IF pt is the root THEN create a new root with children pt and p'' (and key κr) ELSE return(p' = p'', k' = κr ). insert in a nonleaf recursion no overflow with overflow no overflow new child to parent Notes #7

92 Pseudo Code for Insertion in B+tree
Insert(pt, (p, k), (p', k')); \\ technically, the smallest key kmin in pt is also returned \\ (p, k) is a pointer-key pair to be inserted into the subtree rooted at pt; p' is a new sibling \\ of pt, if created, and k' is the smallest key value in p' ; Case 1. pt = (p1, k1, ..., pi, ki, --, pn+1) is a leaf \\ pn+1 is the sequence pointer IF (i < n) THEN insert (p, k) into pt; return(p' = Null, k' = 0); ELSE re-arrange (p1, k1), ..., (pn, kn), and (p, k) into (ρ1, κ1, ..., ρn+1, κn+1); create a new leaf p''; put (ρr+1, κr+1, …, ρn+1, κn+1, --, pn+1) in p''; \\ r = (n+1)/2 put (ρ1, κ1, ..., ρr, κr, --, p'') in pt; \\ pn+1 and p'' are sequence pointers in p'' and pt. IF pt is the root THEN create a new root with children pt and p'' (and key κr+1) ELSE return(p' = p'', k' = κr+1); Case 2. pt is not a leaf find a key ki in pt such that ki-1 ≤ k < ki; Insert(pi , (k, p), (k", p")); IF (p" = Null) THEN return(k' = 0, p' = Null); ELSE IF there is room in pt, THEN insert (k", p") into pt; return(k' = 0, p' = Null); ELSE re-arrange the content in pt and (k", p") into (ρ1, κ1, ..., ρn+1, κn+1, ρn+2); create a new node p''; put (ρr+1, κr+1, …, ρn+1, κn+1, ρn+2, -- ) in p''; \\ r = (n+1)/2 leave (ρ1, κ1, ..., ρr-1, κr-1, ρr , -- ) in pt; IF pt is the root THEN create a new root with children pt and p'' (and key κr) ELSE return(p' = p'', k' = κr ). new root Notes #7

93 Delete in B+tree Notes #7

94 Delete in B+tree Basic idea:
Find the leaf L where the record r should be deleted; If L remains at least half-full after deleting r, then delete r, and return; Else consider the sibling L’ of L; If L’ is more than half-full, then move a record from L’ to L, and return; Else combine L and L’ into a single leaf; But now you need to consider the case of deleting a child from L’s parent … (recursively) Notes #7

95 Delete in B+tree Simple case: the node remains at least half-full after deletion. Re-distribute keys among siblings Coalesce with a sibling and delete a pointer from its father Notes #7

96 Delete in B+tree Simple case: the node remains at least half-full after deletion. Re-distribute keys among siblings Coalesce with a sibling and delete a pointer from its father Notes #7

97 Simple case: Delete key 35
order n=3 Notes #7

98 Simple case: Delete key 35
order n=3 Delete(prt, 35) 105 10 40 3 5 8 10 20 35 40 50 Notes #7

99 Simple case: Delete key 35
order n=3 Delete(prt, 35) 105 10 40 3 5 8 10 20 35 40 50 Delete 35 Notes #7

100 After deletion, the node still keeps at least half-full
Simple case: Delete key 35 order n=3 Delete(prt, 35) 105 10 40 3 5 8 10 20 35 40 50 After deletion, the node still keeps at least half-full Notes #7

101 Simple case: Delete key 35
order n=3 105 10 40 3 5 8 10 20 40 50 Notes #7

102 Delete in B+tree Simple case: the node remains at least half-full after deletion. Re-distribute keys among siblings Coalesce with a sibling and delete a pointer from its father Notes #7

103 Key re-distribution at leaves
p’ k’ p k p” k” i = (n+1)/2  1 t > (n+1)/2 p1 k1 … pi ki --- p* q1 h1 q2 h2 … qt ht --- q* Notes #7

104 Key re-distribution at leaves
p’ k’ p k p” k” i = (n+1)/2  1 t > (n+1)/2 p1 k1 … pi ki --- p* q1 h1 q2 h2 … qt ht --- q* p’ k’ p k p” k” p1 k1 … pi ki q1 h1 --- p* q2 h2 … qt ht --- q* Notes #7

105 Key re-distribution at leaves
p’ k’ p k p” k” i = (n+1)/2  1 t > (n+1)/2 p1 k1 … pi ki --- p* q1 h1 q2 h2 … qt ht --- q* p’ k’ p k p” k” h2 p1 k1 … pi ki q1 h1 --- p* q2 h2 … qt ht --- q* Notes #7

106 Key re-distribution at leaves: Delete 5
order n=3 Notes #7

107 Key re-distribution at leaves: Delete 5
order n=3 Delete(prt, 5) 105 10 40 3 5 10 20 35 40 50 Notes #7

108 Key re-distribution at leaves: Delete 5
order n=3 Delete(prt, 5) 105 10 40 3 5 10 20 35 40 50 Delete 5 Notes #7

109 Key re-distribution at leaves: Delete 5
order n=3 Delete(prt, 5) 105 10 40 3 5 10 20 35 40 50 Notes #7

110 Key re-distribution at leaves: Delete 5
order n=3 Delete(prt, 5) 105 10 40 3 5 10 20 35 40 50 Less than half-full !! Notes #7

111 Key re-distribution at leaves: Delete 5
order n=3 Delete(prt, 5) 105 10 40 3 5 10 20 35 40 50 Look at the sibling, which is more than half-full, so we can redistribute the keysa Notes #7

112 Key re-distribution at leaves: Delete 5
order n=3 Delete(prt, 5) 105 10 40 3 5 10 20 35 40 50 Look at the sibling, which is more than half-full, so we can redistribute the keys Notes #7

113 Key re-distribution at leaves: Delete 5
order n=3 Delete(prt, 5) 105 10 40 redistribution 3 10 20 35 40 50 3 10 20 35 Notes #7

114 Key re-distribution at leaves: Delete 5
order n=3 Delete(prt, 5) 105 10 40 redistribution 20 3 10 20 35 40 50 3 10 20 35 Notes #7

115 Key re-distribution at leaves: Delete 5
order n=3 Delete(prt, 5) 105 20 10 40 redistribution 20 3 10 20 35 40 50 3 10 20 35 Notes #7

116 Key re-distribution at leaves: Delete 5
order n=3 105 20 40 3 10 20 35 40 50 Notes #7

117 Key re-distribution at nonleaves
Notes #7

118 Key re-distribution at nonleaves
p’ k’ p k p” k” i+1 = (n+1)/2  1 t+1> (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 q2 h2 … qt ht qt+1 - Notes #7

119 Key re-distribution at nonleaves
p’ k’ p k p” k” i+1 = (n+1)/2  1 t+1> (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 q2 h2 … qt ht qt+1 - p’ k’ p k p” k” p1 k1 … pi ki pi+1 q1 h1 q2 h2 … qt ht qt+1 - Notes #7

120 Key re-distribution at nonleaves
p’ k’ p k p” k” i+1 = (n+1)/2  1 t+1> (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 q2 h2 … qt ht qt+1 - p’ k’ p k p” k” p1 k1 … pi ki pi q1 q1 h1 q2 h2 … qt ht qt+1 - Notes #7

121 Key re-distribution at nonleaves
p’ k’ p k p” k” i+1 = (n+1)/2  1 t+1> (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 q2 h2 … qt ht qt+1 - p’ k’ p k p” k” p1 k1 … pi ki pi q1 ? q1 h1 q2 h2 … qt ht qt+1 - Notes #7

122 Key re-distribution at nonleaves
p’ k’ p k p” k” i+1 = (n+1)/2  1 t+1> (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 q2 h2 … qt ht qt+1 - p’ k’ p k p” k” p1 k1 … pi ki pi q1 ? q1 h1 q2 h2 … qt ht qt+1 - Notes #7

123 Key re-distribution at nonleaves
p’ k’ p k p” k” i+1 = (n+1)/2  1 t+1> (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 q2 h2 … qt ht qt+1 - p’ k’ p k p” k” p1 k1 … pi ki pi q1 k’ q1 h1 q2 h2 … qt ht qt+1 - Notes #7

124 Key re-distribution at nonleaves
p’ k’ p k p” k” i+1 = (n+1)/2  1 t+1> (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 q2 h2 … qt ht qt+1 - p’ k’ p k p” k” ? p1 k1 … pi ki pi q1 k’ q1 h1 q2 h2 … qt ht qt+1 - Notes #7

125 Key re-distribution at nonleaves
p’ k’ p k p” k” i+1 = (n+1)/2  1 t+1> (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 q2 h2 … qt ht qt+1 - p’ k’ p k p” k” ? p1 k1 … pi ki pi q1 k’ q1 h1 q2 h2 … qt ht qt+1 - Notes #7

126 Key re-distribution at nonleaves
p’ k’ p k p” k” i+1 = (n+1)/2  1 t+1> (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 q2 h2 … qt ht qt+1 - p’ k’ p k p” k” h1 p1 k1 … pi ki pi q1 k’ q1 h1 q2 h2 … qt ht qt+1 - Notes #7

127 Key re-distribution at nonleaves
p’ k’ p k p” k” i+1 = (n+1)/2  1 t+1> (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 q2 h2 … qt ht qt+1 - p’ k’ p k p” k” h1 p1 k1 … pi ki pi q1 k’ q2 h2 … qt ht qt+1 Notes #7

128 Delete in B+tree Simple case: the node remains at least half-full after deletion. Re-distribute keys among siblings Coalesce with a sibling and delete a pointer from its father Notes #7

129 Delete in B+tree Simple case: the node remains at least half-full after deletion. Re-distribute keys among siblings Coalesce with a sibling and delete a pointer from its father Observation: when two siblings both are no more than half full, coalesce them into a single node (which is nearly full) Notes #7

130 Node Coalescence Notes #7

131 Leaf Coalescence Notes #7

132 Leaf Coalescence p’ k’ p k p” k” p1 k1 … pi ki --- p*
i = (n+1)/2  1 t = (n+1)/2 p1 k1 … pi ki --- p* q1 h1 … qt ht --- q* Notes #7

133 Leaf Coalescence p’ k’ p k p” k” p1 k1 … pi ki --- p*
i = (n+1)/2  1 t = (n+1)/2 p1 k1 … pi ki --- p* q1 h1 … qt ht --- q* p’ k’ p k p” k” p1 k1 … pi ki q1 h1 … qt ht - q* q* Notes #7

134 Leaf Coalescence p’ k’ p k p” k” p1 k1 … pi ki --- p*
i = (n+1)/2  1 t = (n+1)/2 p1 k1 … pi ki --- p* q1 h1 … qt ht --- q* p’ k’ p k p” k” p1 k1 … pi ki q1 h1 … qt ht - q* q* Notes #7

135 Leaf coalescence : Delete key 5
Notes #7

136 Leaf coalescence : Delete key 5
order n=3 Delete(prt, 5) 38 10 60 80 3 5 10 20 40 50 60 75 80 90 Notes #7

137 Leaf coalescence : Delete key 5
order n=3 Delete(prt, 5) 38 10 60 80 3 5 10 20 40 50 60 75 80 90 Delete 5 Notes #7

138 Leaf coalescence : Delete key 5
order n=3 Delete(prt, 5) 38 10 60 80 3 5 10 20 40 50 60 75 80 90 Notes #7

139 The sibling is just half-full, so we should coalesce
Leaf coalescence : Delete key 5 order n=3 Delete(prt, 5) 38 10 60 80 3 5 10 20 40 50 60 75 80 90 The sibling is just half-full, so we should coalesce Notes #7

140 Leaf coalescence : Delete key 5
order n=3 Delete(prt, 5) 38 10 60 80 Leaf coalescence 3 10 20 10 20 40 50 60 75 80 90 3 5 10 20 Notes #7

141 Leaf coalescence : Delete key 5
order n=3 Delete(prt, 5) Less than half-full 38 10 60 80 Leaf coalescence 3 10 20 10 20 40 50 60 75 80 90 3 5 10 20 Notes #7

142 half-full, so we can re-distribute pointers at nonleaves
Leaf coalescence : Delete key 5 order n=3 Delete(prt, 5) Less than half-full more than half-full, so we can re-distribute pointers at nonleaves 38 10 60 80 Leaf coalescence 3 10 20 10 20 40 50 60 75 80 90 3 5 10 20 Notes #7

143 half-full, so we can re-distribute pointers at nonleaves
Leaf coalescence : Delete key 5 order n=3 Delete(prt, 5) Less than half-full more than half-full, so we can re-distribute pointers at nonleaves 38 10 60 80 Leaf coalescence 3 10 20 10 20 40 50 60 75 80 90 3 5 10 20 Notes #7

144 half-full, so we can re-distribute pointers at nonleaves
Key re-distribution at Nonleaves order n=3 Delete(prt, 5) Less than half-full more than half-full, so we can re-distribute pointers at nonleaves 38 10 60 80 Leaf coalescence 3 10 20 10 20 40 50 60 75 80 90 3 5 10 20 Notes #7

145 half-full, so we can re-distribute pointers at nonleaves
Key re-distribution at Nonleaves order n=3 Delete(prt, 5) Less than half-full more than half-full, so we can re-distribute pointers at nonleaves 38 60 38 10 60 80 Leaf coalescence 3 10 20 10 20 40 50 60 75 80 90 3 5 10 20 Notes #7

146 half-full, so we can re-distribute pointers at nonleaves
Key re-distribution at Nonleaves order n=3 Delete(prt, 5) Less than half-full more than half-full, so we can re-distribute pointers at nonleaves 38 60 38 10 80 60 80 Leaf coalescence 3 10 20 10 20 40 50 60 75 80 90 3 5 10 20 Notes #7

147 Key re-distribution at Nonleaves
order n=3 60 38 80 3 10 20 40 50 60 75 80 90 Notes #7

148 Nonleaf Coalescence Notes #7

149 Nonleaf Coalescence p’ k’ p k p” k” p1 k1 … pi ki pi+1
i+1 = (n+1)/2  1 t+1= (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 … qt ht qt+1 Notes #7

150 Nonleaf Coalescence p’ k’ p k p” k” p1 k1 … pi ki pi+1
i+1 = (n+1)/2  1 t+1= (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 … qt ht qt+1 p’ k’ p k p” k” p1 k1 … pi ki pi+1 q1 h1 … qt ht qt+1 q1 h1 … qt ht qt+1 Notes #7

151 Nonleaf Coalescence p’ k’ p k p” k” p1 k1 … pi ki pi+1
i+1 = (n+1)/2  1 t+1= (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 … qt ht qt+1 p’ k’ p k p” k” p1 k1 … pi ki pi+1 ? q1 h1 … qt ht qt+1 q1 h1 … qt ht qt+1 Notes #7

152 Nonleaf Coalescence p’ k’ p k p” k” p1 k1 … pi ki pi+1
i+1 = (n+1)/2  1 t+1= (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 … qt ht qt+1 p’ k’ p k p” k” p1 k1 … pi ki pi+1 ? q1 h1 … qt ht qt+1 q1 h1 … qt ht qt+1 Notes #7

153 Nonleaf Coalescence p’ k’ p k p” k” p1 k1 … pi ki pi+1
i+1 = (n+1)/2  1 t+1= (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 … qt ht qt+1 p’ k’ p k p” k” p1 k1 … pi ki pi+1 k q1 h1 … qt ht qt+1 q1 h1 … qt ht qt+1 Notes #7

154 Nonleaf Coalescence p’ k’ p k p” k” p1 k1 … pi ki pi+1
i+1 = (n+1)/2  1 t+1= (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 … qt ht qt+1 p’ k’ p k p” k” p1 k1 … pi ki pi+1 k q1 h1 … qt ht qt+1 q1 h1 … qt ht qt+1 Notes #7

155 Nonleaf coalescence : Delete key 5
order n=3 Notes #7

156 Nonleaf coalescence : Delete key 5
order n=3 Delete(prt, 5) 55 10 60 3 5 10 20 55 58 61 72 Notes #7

157 Nonleaf coalescence : Delete key 5
order n=3 Delete(prt, 5) 55 10 60 3 5 10 20 55 58 61 72 delete 5 Notes #7

158 Nonleaf coalescence : Delete key 5
order n=3 Delete(prt, 5) 55 10 60 3 5 10 20 55 58 61 72 Notes #7

159 Nonleaf coalescence : Delete key 5
order n=3 Delete(prt, 5) 55 10 60 leaf coalescence 3 10 20 10 20 55 58 61 72 3 5 10 20 Notes #7

160 Nonleaf coalescence : Delete key 5
order n=3 Delete(prt, 5) 55 less than half-full 10 60 leaf coalescence 10 20 55 58 61 72 3 10 20 3 5 10 20 Notes #7

161 Nonleaf coalescence : Delete key 5
order n=3 Delete(prt, 5) 55 less than half-full just half-full, so we need to coalesce 10 60 leaf coalescence 10 20 55 58 61 72 3 10 20 3 5 10 20 Notes #7

162 Nonleaf coalescence : Delete key 5
order n=3 55 60 Delete(prt, 5) 55 nonleaf coalescence 55 60 60 leaf coalescence 61 72 3 10 20 10 20 55 58 3 5 10 20 Notes #7

163 Nonleaf coalescence : Delete key 5
order n=3 55 60 Delete(prt, 5) 55 nonleaf coalescence new root 55 60 60 leaf coalescence 61 72 3 10 20 10 20 55 58 3 5 10 20 Notes #7

164 Nonleaf coalescence : Delete key 5
order n=3 55 60 3 10 20 55 58 61 72 Notes #7

165 Pseudo Code for Deletion in a B+tree
Delete(pt, (k,p), belowmin); \\ technically, the smallest key kmin in *ptr is also returned \\ (k,p) is the data record to be deleted from the subtree rooted at pt; belowmin = true if \\ after deletion, pt has fewer than the required min # of pointers; Case 1. pt is a leaf delete (k,p) in pt; IF pt has at least (n+1)/2 data pointers OR pt is the root THEN return (belowmin = false) ELSE return (belowmin = true); Case 2. pt is not a leaf find a key ki in pt such that ki ≤ k < ki+1; Delete(pi , (k, p), belowmin'); IF (not belowmin') THEN return(belowmin= false); ELSE IF pi has an adjacent sibling p' that has more than the required min # of pointers THEN move one key-pointer pair from p' to pi; ELSE combine pi with an adjacent sibling of pi into a single node; IF pt is the root with only one pointer pi THEN pt = pi; return(belowmin= false); IF pt has at least (n+1)/2 pointers OR pt is the root THEN return(belowmin= false) ELSE return(belowmin= true); Notes #7

166 Pseudo Code for Deletion in a B+tree
Delete(pt, (k,p), belowmin); \\ technically, the smallest key kmin in *ptr is also returned \\ (k,p) is the data record to be deleted from the subtree rooted at pt; belowmin = true if \\ after deletion, pt has fewer than the required min # of pointers; Case 1. pt is a leaf delete (k,p) in pt; IF pt has at least (n+1)/2 data pointers OR pt is the root THEN return (belowmin = false) ELSE return (belowmin = true); Case 2. pt is not a leaf find a key ki in pt such that ki ≤ k < ki+1; Delete(pi , (k, p), belowmin'); IF (not belowmin') THEN return(belowmin= false); ELSE IF pi has an adjacent sibling p' that has more than the required min # of pointers THEN move one key-pointer pair from p' to pi; ELSE combine pi with an adjacent sibling of pi into a single node; IF pt is the root with only one pointer pi THEN pt = pi; return(belowmin= false); IF pt has at least (n+1)/2 pointers OR pt is the root THEN return(belowmin= false) ELSE return(belowmin= true); delete at a leaf Notes #7

167 Pseudo Code for Deletion in a B+tree
Delete(pt, (k,p), belowmin); \\ technically, the smallest key kmin in *ptr is also returned \\ (k,p) is the data record to be deleted from the subtree rooted at pt; belowmin = true if \\ after deletion, pt has fewer than the required min # of pointers; Case 1. pt is a leaf delete (k,p) in pt; IF pt has at least (n+1)/2 data pointers OR pt is the root THEN return (belowmin = false) ELSE return (belowmin = true); Case 2. pt is not a leaf find a key ki in pt such that ki ≤ k < ki+1; Delete(pi , (k, p), belowmin'); IF (not belowmin') THEN return(belowmin= false); ELSE IF pi has an adjacent sibling p' that has more than the required min # of pointers THEN move one key-pointer pair from p' to pi; ELSE combine pi with an adjacent sibling of pi into a single node; IF pt is the root with only one pointer pi THEN pt = pi; return(belowmin= false); IF pt has at least (n+1)/2 pointers OR pt is the root THEN return(belowmin= false) ELSE return(belowmin= true); delete at a nonleaf Notes #7

168 Pseudo Code for Deletion in a B+tree
Delete(pt, (k,p), belowmin); \\ technically, the smallest key kmin in *ptr is also returned \\ (k,p) is the data record to be deleted from the subtree rooted at pt; belowmin = true if \\ after deletion, pt has fewer than the required min # of pointers; Case 1. pt is a leaf delete (k,p) in pt; IF pt has at least (n+1)/2 data pointers OR pt is the root THEN return (belowmin = false) ELSE return (belowmin = true); Case 2. pt is not a leaf find a key ki in pt such that ki ≤ k < ki+1; Delete(pi , (k, p), belowmin'); IF (not belowmin') THEN return(belowmin= false); ELSE IF pi has an adjacent sibling p' that has more than the required min # of pointers THEN move one key-pointer pair from p' to pi; ELSE combine pi with an adjacent sibling of pi into a single node; IF pt is the root with only one pointer pi THEN pt = pi; return(belowmin= false); IF pt has at least (n+1)/2 pointers OR pt is the root THEN return(belowmin= false) ELSE return(belowmin= true); delete at a nonleaf recursion Notes #7

169 Pseudo Code for Deletion in a B+tree
Delete(pt, (k,p), belowmin); \\ technically, the smallest key kmin in *ptr is also returned \\ (k,p) is the data record to be deleted from the subtree rooted at pt; belowmin = true if \\ after deletion, pt has fewer than the required min # of pointers; Case 1. pt is a leaf delete (k,p) in pt; IF pt has at least (n+1)/2 data pointers OR pt is the root THEN return (belowmin = false) ELSE return (belowmin = true); Case 2. pt is not a leaf find a key ki in pt such that ki ≤ k < ki+1; Delete(pi , (k, p), belowmin'); IF (not belowmin') THEN return(belowmin= false); ELSE IF pi has an adjacent sibling p' that has more than the required min # of pointers THEN move one key-pointer pair from p' to pi; ELSE combine pi with an adjacent sibling of pi into a single node; IF pt is the root with only one pointer pi THEN pt = pi; return(belowmin= false); IF pt has at least (n+1)/2 pointers OR pt is the root THEN return(belowmin= false) ELSE return(belowmin= true); delete at a nonleaf half-full condition is satisfied recursion Notes #7

170 Pseudo Code for Deletion in a B+tree
Delete(pt, (k,p), belowmin); \\ technically, the smallest key kmin in *ptr is also returned \\ (k,p) is the data record to be deleted from the subtree rooted at pt; belowmin = true if \\ after deletion, pt has fewer than the required min # of pointers; Case 1. pt is a leaf delete (k,p) in pt; IF pt has at least (n+1)/2 data pointers OR pt is the root THEN return (belowmin = false) ELSE return (belowmin = true); Case 2. pt is not a leaf find a key ki in pt such that ki ≤ k < ki+1; Delete(pi , (k, p), belowmin'); IF (not belowmin') THEN return(belowmin= false); ELSE IF pi has an adjacent sibling p' that has more than the required min # of pointers THEN move one key-pointer pair from p' to pi; ELSE combine pi with an adjacent sibling of pi into a single node; IF pt is the root with only one pointer pi THEN pt = pi; return(belowmin= false); IF pt has at least (n+1)/2 pointers OR pt is the root THEN return(belowmin= false) ELSE return(belowmin= true); delete at a nonleaf half-full condition is satisfied recursion key re-distribution Notes #7

171 Pseudo Code for Deletion in a B+tree
Delete(pt, (k,p), belowmin); \\ technically, the smallest key kmin in *ptr is also returned \\ (k,p) is the data record to be deleted from the subtree rooted at pt; belowmin = true if \\ after deletion, pt has fewer than the required min # of pointers; Case 1. pt is a leaf delete (k,p) in pt; IF pt has at least (n+1)/2 data pointers OR pt is the root THEN return (belowmin = false) ELSE return (belowmin = true); Case 2. pt is not a leaf find a key ki in pt such that ki ≤ k < ki+1; Delete(pi , (k, p), belowmin'); IF (not belowmin') THEN return(belowmin= false); ELSE IF pi has an adjacent sibling p' that has more than the required min # of pointers THEN move one key-pointer pair from p' to pi; ELSE combine pi with an adjacent sibling of pi into a single node; IF pt is the root with only one pointer pi THEN pt = pi; return(belowmin= false); IF pt has at least (n+1)/2 pointers OR pt is the root THEN return(belowmin= false) ELSE return(belowmin= true); delete at a nonleaf half-full condition is satisfied recursion key re-distribution node coalescence Notes #7

172 Pseudo Code for Deletion in a B+tree
Delete(pt, (k,p), belowmin); \\ technically, the smallest key kmin in *ptr is also returned \\ (k,p) is the data record to be deleted from the subtree rooted at pt; belowmin = true if \\ after deletion, pt has fewer than the required min # of pointers; Case 1. pt is a leaf delete (k,p) in pt; IF pt has at least (n+1)/2 data pointers OR pt is the root THEN return (belowmin = false) ELSE return (belowmin = true); Case 2. pt is not a leaf find a key ki in pt such that ki ≤ k < ki+1; Delete(pi , (k, p), belowmin'); IF (not belowmin') THEN return(belowmin= false); ELSE IF pi has an adjacent sibling p' that has more than the required min # of pointers THEN move one key-pointer pair from p' to pi; ELSE combine pi with an adjacent sibling of pi into a single node; IF pt is the root with only one pointer pi THEN pt = pi; return(belowmin= false); IF pt has at least (n+1)/2 pointers OR pt is the root THEN return(belowmin= false) ELSE return(belowmin= true); delete at a nonleaf half-full condition is satisfied recursion key re-distribution node coalescence decide if a new root Notes #7

173 Pseudo Code for Deletion in a B+tree
Delete(pt, (k,p), belowmin); \\ technically, the smallest key kmin in *ptr is also returned \\ (k,p) is the data record to be deleted from the subtree rooted at pt; belowmin = true if \\ after deletion, pt has fewer than the required min # of pointers; Case 1. pt is a leaf delete (k,p) in pt; IF pt has at least (n+1)/2 data pointers OR pt is the root THEN return (belowmin = false) ELSE return (belowmin = true); Case 2. pt is not a leaf find a key ki in pt such that ki ≤ k < ki+1; Delete(pi , (k, p), belowmin'); IF (not belowmin') THEN return(belowmin= false); ELSE IF pi has an adjacent sibling p' that has more than the required min # of pointers THEN move one key-pointer pair from p' to pi; ELSE combine pi with an adjacent sibling of pi into a single node; IF pt is the root with only one pointer pi THEN pt = pi; return(belowmin= false); IF pt has at least (n+1)/2 pointers OR pt is the root THEN return(belowmin= false) ELSE return(belowmin= true); report if pt is less than half-full Notes #7

174 Pseudo Code for Deletion in a B+tree
Delete(pt, (k,p), belowmin); \\ technically, the smallest key kmin in *ptr is also returned \\ (k,p) is the data record to be deleted from the subtree rooted at pt; belowmin = true if \\ after deletion, pt has fewer than the required min # of pointers; Case 1. pt is a leaf delete (k,p) in pt; IF pt has at least (n+1)/2 data pointers OR pt is the root THEN return (belowmin = false) ELSE return (belowmin = true); Case 2. pt is not a leaf find a key ki in pt such that ki ≤ k < ki+1; Delete(pi , (k, p), belowmin'); IF (not belowmin') THEN return(belowmin= false); ELSE IF pi has an adjacent sibling p' that has more than the required min # of pointers THEN move one key-pointer pair from p' to pi; ELSE combine pi with an adjacent sibling of pi into a single node; IF pt is the root with only one pointer pi THEN pt = pi; return(belowmin= false); IF pt has at least (n+1)/2 pointers OR pt is the root THEN return(belowmin= false) ELSE return(belowmin= true); Notes #7

175 B+tree deletions in practice
Often, coalescing is not implemented Too hard and not worth it! Notes #7


Download ppt "CPSC-629 Analysis of Algorithms"

Similar presentations


Ads by Google