The document discusses the properties and structure of B-trees, including that nodes have a minimum and maximum number of keys, internal nodes have child pointers, keys separate key ranges in subtrees, leaves have the same depth defining the tree height, and splitting occurs when nodes exceed the maximum keys.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
23 views21 pages
08 B Tree
The document discusses the properties and structure of B-trees, including that nodes have a minimum and maximum number of keys, internal nodes have child pointers, keys separate key ranges in subtrees, leaves have the same depth defining the tree height, and splitting occurs when nodes exceed the maximum keys.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 21
B-Trees
Dr. Ashish Sharma
Properties
A B-tree T is a rooted tree (with root root[T]) having
the following properties. 1. Every node x has the following fields:
a. n[x], the number of keys currently stored in node x,
b. the n[x] keys themselves, stored in nondecreasing order: key1[x] ≤ key2[x] ≤ ……. ≤ keyn[x][x], and c. leaf [x], a boolean value that is TRUE if x is a leaf and FALSE if x is an internal node. Cont… 2. If x is an internal node, it also contains n[x] + 1 pointers c1[x], c2[x], . . . , cn[x]+1[x] to its children. Leaf nodes have no children, so their ci fields are undefined. 3. The keys keyi[x] separate the ranges of keys stored in each subtree: if ki is any key stored in the subtree with root ci[x], then k1 ≤ key1[x] ≤ k2 key2[x] ≤ ….. ≤ keyn[x][x] kn[x]+1 . 4. Every leaf has the same depth, which is the tree's height h. David Luebke 3 06/06/24 Cont… 5. There are lower and upper bounds on the number of keys a node can contain. These bounds can be expressed in terms of a fixed integer t ≥ 2 called the minimum degree of the B-tree: ● a. Every node other than the root must have at least t - 1 keys. Every internal node other than the root thus has at least t children. If the tree is nonempty, the root must have at least one key. ● b. Every node can contain at most 2t - 1 keys. Therefore, an internal node can have at most 2t children. We say that a node is full if it contains exactly 2t - 1 keys.
David Luebke 4 06/06/24
Cont…
● The simplest B-tree occurs when t = 2. Every
internal node then has either 2, 3, or 4 children, and we have a 2-3-4 tree. In practice, however, much larger values of t are typically used.
David Luebke 5 06/06/24
Theorem : If n ≥ 1, then for any n-key B-tree T of height h and minimum degree t ≥ 2, then
David Luebke 6 06/06/24
Cont… ● Proof If a B-tree has height h, the number of its nodes is minimized when the root contains one key and all other nodes contain t - 1 keys. ● In this case, there are 2 nodes at depth 1, 2t nodes at depth 2, 2t2 nodes at depth 3, and so on, until at depth h there are 2th-1 nodes. ● Figure illustrates such a tree for h = 3. Thus, the number n of keys satisfies the inequality
David Luebke 7 06/06/24
Cont…
David Luebke 8 06/06/24
B-TREE-SPLIT-CHILD(x,i,y) 1 z ←ALLOCATE-NODE() 2 leaf[z] ← leaf[y] 3 n[z] ← t - 1 4 for j ←1 to t - 1 5 do keyj[z] ← keyj+t[y] 6 if not leaf [y] 7 then for j ←1 to t 8 do cj[z] ← cj+t[y] 9 n[y] ← t - 1 David Luebke 9 06/06/24 B-TREE-SPLIT-CHILD(x,i,y) 10 for j ←n[x] + 1 downto i + 1 11 do cj+1[x] ←cj[x] 12 ci+1[x] ←z 13 for j ← n[x] downto i 14 do keyj+1[x] ← keyj[x] 15 keyi[x] ← keyt[y] 16 n[x] ←n[x] + 1 17 DISK-WRITE(y) 18 DISK-WRITE(z) 19 DISK-WRITE(x) David Luebke 10 06/06/24 Spliting a node in B-Tree
David Luebke 11 06/06/24
Example t=3 so a node can hold at most 5 keys
David Luebke 12 06/06/24
Let us understand the algorithm with an example tree of minimum degree ‘t’ as 3 and a sequence of integers 10, 20, 30, 40, 50, 60, 70, 80 and 90 in an initially empty B-Tree. Initially root is NULL. Let us first insert 10.
David Luebke 13 06/06/24
Let us now insert 20, 30, 40 and 50. They all will be inserted in root because the maximum number of keys a node can accommodate is 2*t – 1 which is 5.
David Luebke 14 06/06/24
Let us now insert 20, 30, 40 and 50. They all will be inserted in root because the maximum number of keys a node can accommodate is 2*t – 1 which is 5.
David Luebke 15 06/06/24
Let us now insert 60. Since root node is full, it will first split into two, then 60 will be inserted into the appropriate child.
David Luebke 16 06/06/24
Let us now insert 60. Since root node is full, it will first split into two, then 60 will be inserted into the appropriate child.
David Luebke 17 06/06/24
Let us now insert 70 and 80. These new keys will be inserted into the appropriate leaf without any split.
David Luebke 18 06/06/24
Let us now insert 70 and 80. These new keys will be inserted into the appropriate leaf without any split.
David Luebke 19 06/06/24
Let us now insert 90. This insertion will cause a split. The middle key will go up to the parent.
David Luebke 20 06/06/24
Let us now insert 90. This insertion will cause a split. The middle key will go up to the parent.