Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Memory
• Disks many times slower than memory:
› Processor measured in GH = 109 cycles per
B-Trees second
› Main memory measured in microsec. = 106 per
second
CSE 326 › Disk seek measured in miliseconds = 103 per
second
Data Structures • i.e. ~ 1 million instructions per disk lookup
Lecture 10 • Measuring runtime by pointer lookups
meaningless if data can’t fit in main memory
2/3/05 B-Trees - Lecture 10 2
1
B-Trees Example
B-Trees are multi-way search trees commonly used in database
systems or other applications where data is stored externally on • B-tree of order 3 has 2 or 3 children per
disks and keeping the tree shallow is important.
node
A B-Tree of order M has the following properties: 13:-
1. The root is either a leaf or has between 2 and M children.
2. All nonleaf nodes (except the root) have between M/2 6:11 17:-
and M children.
3. All leaves are at the same depth.
Each (non-leaf) internal node of a B-tree has: Each leaf node of a B-tree has:
› Between M/2 and M children. › Between M/2 and M keys and pointers.
› up to M-1 keys k1 < k2 < ... < kM-1
k1 ... ki-1 ki ... kM
k1 ... ki-1 ki ... kM-1
Keys point to
Keys are ordered so that: data on other
Keys are ordered so that: k1 < k2 < ... < kM-1 pages.
k1 < k2 < ... < kM-1
2/3/05 B-Trees - Lecture 10 9 2/3/05 B-Trees - Lecture 10 10
2
Inserting into B-Trees Insert Example
• Insert X: Do a Find on X and find appropriate leaf node
› If leaf node is not full, fill in empty slot with X 13:-
• E.g. Insert 5
› If leaf node is full, split leaf node and adjust parents up to root 17:-
6:11
node
• E.g. Insert 9
13:-
3 4 6 7 89 11 12 13 14 17 18
6:11 17:-
3 4 6 7 8 11 12 13 14 17 18
13:- 8:13
3 4 6 7 89 11 12 13 14 17 18 3 4 6 7 89 11 12 13 14 17 18
6:11 17:- 3 4 6 7 8 11 12 13 14 18
3 4 6 7 8 11 12 13 14 17 18
3
Delete Example Delete Example
13:- 11:-
3 4 6 7 8 11 12 13 14 18 3 4 6 7 8 11 12 13 14 18