Lec7 - B-Trees
Lec7 - B-Trees
1
B-Trees
Considerations for disk-based storage
systems.
Indexed Sequential Access Method
(ISAM)
m-way search trees
B-trees
2
Data Layout on Disk
• Track: one ring
• Sector: one pie-shaped piece.
• Block: intersection of a track and a sector.
3
Considerations for Disk Based
Dictionary Structures
Use a disk-based method when the dictionary is too big to
fit in RAM at once.
5
ISAM (Continued)
6
ISAM (Continued)
To perform a get(k) operation:
7
ISAM Limitations
Problems with ISAM:
8
A Solution: B-Trees
Idea 1: Use m-way search trees.
(ISAM uses a root and one level under the root.)
m-way search trees can be as high as we need.
9
B-Tree Example with m = 5
12
2 3 8 13 27
12
2 3 8 10 13 27
We find the location for 10 by following a path from the root using the
stored key values to guide the search.
The search falls out the tree at the 4th child of the 1st child of the root.
The 1st child of the root has room for the new element, so we store it
there.
11
Insert 11
12
2 3 8 10 11 13 27
We fall out of the tree at the child to the right of key 10.
But there is no more room in the left child of the root to hold 11.
Therefore, we must split this node...
12
Insert 11 (Continued)
8 12
2 3 10 11 13 27
The m + 1 children are divided evenly between the old and new nodes.
The parent gets one new child. (If the parent become overfull, then it,
too, will have to be split).
13
Remove 8
8 12
2 3 10 11 13 27
12
2 3 10 11 13 27
The root contains one fewer key, and has one fewer child.
15
Remove 13
12
2 3 10 11 13 27
16
Remove 13 (Cont)
11
2 3 10 12 27
17
Remove 11
11
2 3 10 12 27
18
Remove 11 (Cont)
10
2 3 12 27
19
Remove 2
10
2 3 12 27
20
Remove 2 (Cont)
3 10 12 27
The result is illegal, because the root does not have at least 2 children.
Therefore, we must remove the root, making its child the new root.
21
Remove 2 (Cont)
3 10 12 27
22
Insert 49
3 10 12 27
23
Insert 49 (Cont)
3 10 12 27 49
Adding this key make the node overfull, so it must be split into two.
But this node was the root.
So we must construct a new root, and make these its children.
24
Insert 49 (Cont)
12
3 10 27 49
25
B-Tree performance
26
2-3 Trees
A B-tree of order m is a kind of m-way search
tree.
A B-Tree of order 3 is called a 2-3 Tree.
In a 2-3 tree, each internal node has either 2
or 3 children.
In practical applications, however, B-Trees of
large order (e.g., m = 128) are more common
than low-order B-Trees such as 2-3 trees.
27