B-Trees DS
B-Trees DS
B-Trees
Considerations for disk-based storage
systems.
Indexed Sequential Access Method
(ISAM)
m-way search trees
B-trees
Data Layout on Disk
• Track: one ring
• Sector: one pie-shaped piece.
• Block: intersection of a track and a sector.
Disk Block Access Time
Seek time = maximum of
Time for the disk head to move to the correct track.
Time for the beginning of the correct sector to spin round
to the head. (Some authors use “latency” as the term for this component,
or they use latency to refer to all of what we are calling seek time.)
Transfer time =
Time to read or write the data.
(Approximately the time for the sector to spin by the head).
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.
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...
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).
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.
Remove 13
12
2 3 10 11 13 27
11
2 3 10 12 27
11
2 3 10 12 27
10
2 3 12 27
Remove 2
10
2 3 12 27
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.
Remove 2 (Cont)
3 10 12 27
3 10 12 27
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.
Insert 49 (Cont)
12
3 10 27 49