0% found this document useful (0 votes)
117 views28 pages

DB2 4 BplusTreeExample

The document describes a B+ tree structure and provides an example of keys being inserted and deleted. It shows the tree after inserting keys 1, 3, 5, 7, 9, 2, 4, 6, 8, 10, and then after deleting keys 9, 7, and 8.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
117 views28 pages

DB2 4 BplusTreeExample

The document describes a B+ tree structure and provides an example of keys being inserted and deleted. It shows the tree after inserting keys 1, 3, 5, 7, 9, 2, 4, 6, 8, 10, and then after deleting keys 9, 7, and 8.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Example

 of  B+  tree  

1  
B+  Tree  Example  
•  A  balanced  tree  
•  Each  node  can  have  at  most  m  key  fields  and  m+1  pointer  
fields  
•  Half-­‐full  must  be  sa@sfied  (except  root  node):  
•  m  is  even  and  m=2d  
–  Leaf  node  half  full:  at  least  d  entries  
–  Non-­‐leaf  node  half  full:  at  least  d  entries  
•  m  is  odd  and  m  =  2d+1  
–  Leaf  node  half  full:  at  least  d+1  entries  
–  Non-­‐leaf  node  half  full:  at  least  d  entries  (i.e.,  d+1  
pointers)  

2  
Show  the  tree  aLer  inser@ons  
•  Suppose  each  B+-­‐tree  node  can  hold  up  to  4  
pointers  and  3  keys.  
•  m=3  (odd),  d=1  
•  Half-­‐full  (for  odd  m  value)  
–  Leaf  node,  at  least  2  (d+1)  entries  
–  Non-­‐leaf  nodes,  at  least  2  (d+1)  pointers  (1  entry)  
•  Insert  1,  3,  5,  7,  9,  2,  4,  6,  8,  10  

3  
Insert  1,  3,  5,  7,  9,  2,  4,  6,  8,  10  
•  Insert  1  

4  
Insert  1,  3,  5,  7,  9,  2,  4,  6,  8,  10  
1

•  Insert  3,  5  

5  
Insert  1,  3,  5,  7,  9,  2,  4,  6,  8,  10  
1

•  Insert  3,  5  
1 3 5

6  
Insert  1,  3,  5,  7,  9,  2,  4,  6,  8,  10  
1 3 5

•  Insert  7  

7  
Insert  1,  3,  5,  7,  9,  2,  4,  6,  8,  10  
1 3 5

•  Insert  7  

1 3 5 7

8  
Insert  1,  3,  5,  7,  9,  2,  4,  6,  8,  10  
5

1 3 5 7

•  Insert  9  

9  
Insert  1,  3,  5,  7,  9,  2,  4,  6,  8,  10  
5

1 3 5 7

•  Insert  9  

1 3 5 7 9

10  
Insert  1,  3,  5,  7,  9,  2,  4,  6,  8,  10  
5

1 3 5 7 9

•  Insert  2  

11  
Insert  1,  3,  5,  7,  9,  2,  4,  6,  8,  10  
5

1 3 5 7 9

•  Insert  2  
5

1 2 3 5 7 9

12  
Insert  1,  3,  5,  7,  9,  2,  4,  6,  8,  10  
5

1 2 3 5 7 9

•  Insert  4  

13  
Insert  1,  3,  5,  7,  9,  2,  4,  6,  8,  10  
5

1 2 3 5 7 9

•  Insert  4  
3 5

1 2 3 4 5 7 9

14  
Insert  1,  3,  5,  7,  9,  2,  4,  6,  8,  10  
3 5

1 2 3 4 5 7 9

•  Insert  6  

15  
Insert  1,  3,  5,  7,  9,  2,  4,  6,  8,  10  
3 5

1 2 3 4 5 7 9

•  Insert  6  

3 5 7

1 2 3 4 5 6 7 9

16  
Insert  1,  3,  5,  7,  9,  2,  4,  6,  8,  10  
3 5 7

1 2 3 4 5 6 7 9

•  Insert  8  

17  
Insert  1,  3,  5,  7,  9,  2,  4,  6,  8,  10  
3 5 7

1 2 3 4 5 6 7 9

•  Insert  8  
3 5 7

1 2 3 4 5 6 7 8 9

18  
Insert  1,  3,  5,  7,  9,  2,  4,  6,  8,  10  
3 5 7

1 2 3 4 5 6 7 8 9

•  Insert  10  

19  
Insert  1,  3,  5,  7,  9,  2,  4,  6,  8,  10  
3 5 7

1 2 3 4 5 6 7 8 9

•  Insert  10  
7

3 5 9

7 8 9 10

1 2 3 4 5 6
20  
•  Dele@on  

21  
Show  the  tree  aLer  dele@ons  
9

3 5 7 11

9 10 11 12

1 2 3 4 5 6 7 8

•  Remove  9,  7,  8  

22  
9

3 5 7 11

9 10 11 12

1 2 3 4 5 6 7 8

•  ALer  removing  9  

23  
9

3 5 7 11

9 10 11 12

1 2 3 4 5 6 7 8

•  ALer  removing  9  
7

3 5 9

7 8 10 11 12

1 2 3 4 5 6
24  
Remove  9,  7,  8  
7

3 5 9

7 8 10 11 12

1 2 3 4 5 6

•  ALer  removing  7  

25  
Remove  9,  7,  8  
7

3 5 9

7 8 10 11 12

1 2 3 4 5 6

•  ALer  removing  7  
7

3 5 11

8 10 11 12

1 2 3 4 5 6
26  
Remove  9,  7,  8  
7

3 5 11

8 10 11 12

1 2 3 4 5 6

•  ALer  removing  8  

27  
Remove  9,  7,  8  
7

3 5 11

8 10 11 12

1 2 3 4 5 6

•  ALer  removing  8  
3 5 7

1 2 3 4 5 6 10 11 12

28  

You might also like