Professional Documents
Culture Documents
What is a B+ Tree
Contd
Example B+-tree
9
5
1 3
16 30
5 6
index node
leaf/data node
16 17
30 40
+
B
Trees
j a0 k 1 a1 k 2 a2 k j aj
j = number of keys in node.
ai is a pointer to a subtree.
ki <= smallest key in subtree ai and > largest in ai-1.
B+ Tree - Example
Answer
Benefits of B+ Tree
Every data structure has its benefit to solve a
particular problem over other data structures.
The two main benefits of B+ tree are:
Based on its definition, it is easy to maintain
its balance.
For example:
Cont
B+-tree overview
B-tree structure
of guide keys
Linked-list structure
of records
Properties
The leaf nodes of a B+-tree form a linked-list of nodes.
The interior nodes of the B+-tree are treated as in a Btree structure to search for a certain key range.
Searching
All the keys in the left child of a key have keys less
than that key, and all the keys in the right child are
greater than, or equal to the key.
Search the same way as done for B-trees. The
internal node keys guide the search to the record in a
leaf node.
The leaf nodes in a B+-tree are linked together in a
linked-list structure to facilitate range queries as
discussed earlier.
The key at the start of the range is searched first.
Subsequently, the leaf node linked-list structure is
traversed until the key at the end of the range is
found.
Searching
B+ Tree Insertion
10
12
23
33
48
33
Insert 50:
10
12
23
33
10
12
15
18
20
48
18
21
23
31
50
33
48
33
45
47
48
50
52
Insertion Example #1
25 28 30
Insertion
Result:
Insertion
Insertion
50
50 55
55
60 65
60
70
65 70
Overflow
Insertion
Index Page
Full
Action
NO
NO
YES
NO
YES
YES
Insertion
Overflow
.
75 80 85 90 95
25 50 60 75 85
75 80 85 90 95
25 50
60 75 85
Insertion
Insert Example #2
9
5
1 2
16 30
5 6
16 17 30 40
23
23
Insert
9
5
16 30
2 3
5 6
16 17 30 40
Insert
9
17
2 5
2 3
16 30
5 6
16
17 18
30 40
Insert
17
2 5
2 3
16
5 6
30
16
17 18
30 40
Insert
9 17
2 5
2 3
16
5 6
30
16
17 18
30 40
B+ Tree Deletion
Deletion Example #1
This is
OK.
60
65
Deletion
Result:
Deletion
But
This is
OK.
28 30
Deletion
Add 28
Deletion
65
50 55
65
Underflow
Deletion
Action
NO
NO
YES
NO
YES
YES
Delete Example #2
9
2 5
2 3
16 30
5 6
16 17 30 40
Delete
9
2 5
2 3
16 30
5 6
17
30 40
Delete
9
2 5
2 3
16 30
5 6
17
30 40
Delete
9
3 5
16 30
5 6
17
30 40
Delete
9
3 5
16 30
5 6
17
30 40
Delete
9
16 30
5 6
17
30 40
Delete
9
16 30
6
17
30 40
Delete
9
30
17
30 40
Delete
9
16 30
6
17
30 40
Delete
9
16 30
5
17
30 40
Delete
16
30
17
30 40
Delete 9.
Delete
16
30
5
17
30 40
Delete
16 30
17
30 40
Index files
What file structures can we use to organise a large collection
of records stored in secondary storage?
Hash tables provide outstanding performance for searches of the form
find a record with the key value k
They are not suited for searches such as find all records whose key
value has the same property or lies within a given range.
There may be several keys for a record:
The primary key is a unique identifier for a record. Ex., student
number
A secondary key is some other record field which which does not
necessarily have unique values for each record. Ex., date of birth or
G.P.A.
Most searches are done using secondary keys. Ex., find all students
with a G.P.A. greater than 3.6.
Rec #
GPA
Student #
Name
Addr
...
Primary key
index
Secondary key
index
Main database
There is one primary index file and several secondary index files in
a database.
Sorted linear lists may be used for index files, but they are
unsuitable for databases with frequent updates. [Why?]
Tree indexing solves this problem.
B+-trees are the standard file organisation for application requiring
insertion, deletion and key range searches.
B+-trees are a variant of B-trees (described next).