Professional Documents
Culture Documents
typedef struct nt {
T k1, k2;
int binary;
struct nt * p1, * p2, * p3;
} 23treenode;
binary p1 k1 p2 k2 p3
Operations:
Insert node
Delete node
Search node
10
14 8 10
14 8 14
8 14
2 10 8 10 8 10
9 12
2 8 14 2 9 14 2 9 12 14
15 10 5 10
8 14 8 14
2 9 12 15 2 5 9 12 15
10 11 10
20
14 8 14
8
9 15 20 2 5 9 11 12 15 20
2 5 12
Center for Distributed Computing, Jadavpur University
INSERTION EXAMPLES …
1 10
17 10
2 8 14
2 8 14 17
1 5 9 11 12 15 20
5 9 11 12 15 20
1
21 10
2 8 14 17
5 9 11 12 15 20 21
1
Center for Distributed Computing, Jadavpur University
DELETION EXAMPLES
10
2 8 14 17
5 9 11 12 15 20 21
1
21 10
2 8 14 17
5 9 11 12 15 20
1
Center for Distributed Computing, Jadavpur University
DELETION EXAMPLES …
10 9
2 14 17
1 5 8 11 12 20
15
1 9
5 14 17
2 11 12 15 20
8
Center for Distributed Computing, Jadavpur University
DELETION EXAMPLES …
8 14
9 17
11 12 15
2 5 20
15 9 14
2 5 11 12 17 20
10 20 30 40
20
15
10 15 30 40
35, 7, 26,18
20
7 10 15 18 26 30 35 40
Center for Distributed Computing, Jadavpur University
Insertion Examples …
20 30
22
7 10 15 18 22 26 35 40
10 20 30
5
5 7 15 18 22 26 35 40
10 20 30
42 13 46 27 8
5 7 8 13 15 18 22 26 27 35 40 42 46
10 20 30 40
32
32 35 42 46
5 7 8 13 15 18 22 26 27
10 20 30 40
38 24 45
5 7 8 13 15 18 22 24 26 27 32 35 38 42 45 46
25
25
10 20 30 40
5 7 8 13 15 18 22 24
26 27 32 35 38 42 45 46
Center for Distributed Computing, Jadavpur University
Deletion examples
24
25 45
10 18
30 40
5 7 8
13 15 20 22
26 27 32 35 38 42 46
24 22 22
10 18 10
5 7 8 13 15 20 5 7 8 13 15 18 20
10 22 30 40
27 32 35 38 42 46
5 7 8 13 15 18 20 26
Center for Distributed Computing, Jadavpur University
Deletion examples …
38 32 10 22 30
5 7 8 13 15 18 20 26 27 35 40 42 46
8 27 10 22 35
5 7 13 15 18 20 26 30 40 42 46
Center for Distributed Computing, Jadavpur University
Deletion examples …
46 13 42 10 22
5 7 15 18 20 26 30 35 40
5 15 22
7 10 18 20 26 30 35 40
22 15 30
7 10 18 20 26 35 40
18 15 30
7 10 20 26 35 40
Delete 26 , 7 , 35 , 15
Center for Distributed Computing, Jadavpur University
B+ Tree
Internal node
(NodePointer, Key)*(M-1) |NodePointer in each node
First i keys are currently in use
k0 k1 … ki-1 __ … __
0 1 i-1 M-2
Leaf node
– (Key, DataPointer)* L in each node
…
– first j Keys currently in use
k0 k1 kj-1 __ … __
0 1 L-1
Data for k0 Data for k2 Data for kj-1University
Center for Distributed Computing, Jadavpur
Example
3 15 20 30 50
1 2 10 11 12 20 25 26 40 42
3 5 6 9 15 17 30 32 33 36 50 60 70
Just compare the key value with the data in the tree,
then return the result.
For example: find the value 45, and 15 in below tree.
Result:
1. For the value of 45, not found.
2. For the value of 15, return the position where the
pointer located.
25 28 30
Fits inside the
leaf
Center for Distributed Computing, Jadavpur University
Insertion
Result:
50 55 60 65 70
Does not
fit inside
50 55 60 65 70 the leaf
IF the next level index node is full, continue splitting the index nodes.
Center for Distributed Computing, Jadavpur University
Insertion
75 80 85 90 95
Leaf node
full, split 75 80 85 90 95 25 50 60 75 85
the leaf.
Center for Distributed Computing, Jadavpur University
Insertion
OK. Node
>=50% full 60 65
Center for Distributed Computing, Jadavpur University
Deletion
Result:
But…
28 30
This is
OK. Center for Distributed Computing, Jadavpur University
Deletion
Add 28
65
Less than
50 55 65 50% full
• For a B+ Tree:
• It is “easy” to maintain its balance
– Insertion/Deletion complexity O(logM/2)
• The disk based searching time is shorter than most
of other types of trees because branching factor is
high