This document provides an overview of B-trees, which are balanced search trees used to store large datasets efficiently on disk. It discusses the key properties of B-trees, including their height, minimum node size of t keys, and ability to reduce disk accesses. The basic operations of insertion and deletion are explained through examples, along with the process of splitting or merging nodes when they become too full or empty. B-trees allow searching in O(log n) time and are commonly used in databases and file systems to enable fast indexed retrieval of data.
2. Content
Introduction
B-Tree Properties
The Height of a B-Tree
Basic Operation in a B-Tree
Inserting
Deleting
Time Complexity
Usage of B-Tree
References
2
4. Introduction:
In case of too large data that could not be fit in a main memory
So, that’s require to access the disk multiple of times
Accessing the disk requires long time
We need to reduce the number of disk access!
The solution is to use the B-Tree, which gives more branches with
less height
4
5. B-Tree
B-Tree: is a balanced rooted tree whose root is T root.
Properties of B- Tree:
1. For every node x in B- Tree:
a. x.n the number of keys in x node
b. The x.n keys themselves x. key1, x. key2, …, x. keyn (increasing
order)
c. x.leaf is a Boolean value that is true if x is a leaf & false if x is an
internal node
x.n
x. 𝒌𝒆𝒚 𝟏 x. 𝒌𝒆𝒚 𝟐 x. 𝒌𝒆𝒚 𝟑
5
6. 10 16
1 2 3
9 11 12 13 14 17 20
Cont. Properties of B- Tree:
…
1. Each internal node x also contains x.n+1 pointers x. 𝒄 𝟏, x. 𝒄 𝟐, …,
x. 𝒄 𝒙.𝒏+𝟏
2. The keys x. 𝒌𝒆𝒚𝐢 separates the ranges of keys in the subtree x. 𝒄𝐢
as 𝐤 𝐢 <= x. 𝒌𝒆𝒚𝐢 <= x. 𝒌𝒆𝒚𝐢+𝟏<= …<= x. 𝒌𝒆𝒚 𝒏 <=x. 𝒌𝒆𝒚 𝒏+𝟏
1 2 3
…
x. 𝒄 𝟏 x. 𝒄 𝟐 x. 𝒄 𝟑
6
7. 4. All the leaves have the same depth which is the tree’s height h
o h <= 𝑙𝑜𝑔𝑡
𝑛+1
2
5. Nodes have upper and lower bounds of the keys they can contain,
the minimum degree of the B- Tree is t >= 2
a. Every node other than the root must have at least t-1 keys
o The internal node has at least t children
b. Every node may contain the root at most 2t-1 keys
o The internal node has at most 2t children
Cont. Properties of B- Tree:
7
17. Example 2: (Insertion into B- Tree)
The new B-Tree after splitting
7 13 16 20 24
1 2 3 4 5 10 11 14 15 18 19 25 2621 22
17
18. Insert key = 17?
o if k > x.𝑘𝑒𝑦4 ? => 17 > 22
o B-TREE-INSERT-NONFULL(x. 𝑐4 .n, 17)
o …
x.𝑘𝑒𝑦2
The B-Tree after inserting key = 17
18
19. Deleting a key in a B-Tree
1. If the key k is in node x and x is a leaf, delete the key k from x.
2. If the key k is in node x and x is an internal node, do the
following:
a. If the child y that precedes k in node x has at least t keys, then
find the predecessor of k in the subtree rooted at y. then
delete k and replace k by its predecessor
b. If y has fewer than t keys, then, look at the next z child that
follows y child if z has at least t keys, then find the successor
of k then delete the k and replace it with its successor.
c. If both y and z have only t-1 keys, merge k with all keys in z
to the child y, then delete the k from y
19
20. Deleting a key in a B-Tree
3. If the key k is not present in internal node x, determine the
root x.𝒄𝒊 of the appropriate subtree that must contain k. Note:
necessary to guarantee that we descend to a node containing at
least t keys, do the following:
a. If x.𝒄𝒊 has only t -1 keys but has an immediate sibling with at
least t keys, give x.𝑐𝑖 an extra key by moving a key from x
down into x.𝑐𝑖, moving a key from x.𝑐𝑖’s immediate left or
right sibling up into x. then delete the key
b. If x.𝑐𝑖 and both of x.𝑐𝑖 ’s immediate siblings have t -1 keys,
merge x.𝒄𝒊 with one sibling, which involves moving a key
from x down into the new merged node to become the median
key for that node, then delete the key
20
21. Example 1: Deleting a key in a B-Tree
Delete key 6:
Key 6 is in a leaf node, this is Case 1 , Just delete it
21
t=3
22. Example 2: Deleting a key in a B-Tree
Delete key 13:
Key 6 is in a leaf node, this is Case 2,
22
23. Example 2: Deleting a key in a B-Tree
Delete key 13:
Key 6 is in a leaf node, this is Case 2,
Case 2.a delete k and find its predecessor and place it in key’s
position
23
24. Example 2: Deleting a key in a B-Tree
Delete key 13:
Key 6 is in a leaf node, this is Case 2,
Case 2.a delete k and find its predecessor and place it in key’s
position
24
25. Time complexity:(insert & delete)
It takes O(h) for a B-Tree of height h in disk operation
CPU time takes O(th)
= O (t 𝑙𝑜𝑔𝑡 n )
25
26. Usage of B-Tree
Database: useful in searching
File system: in NTFS directory to make finding an entry faster
26
Unindexed and unsorted data => O(n)
Key n
B-Tree => O(log n)
27. References
1 Cormen, T., Leiserson, C., Rivest, R. and Stein, C. (2014). Introduction to
algorithms. Cambridge, Massachusetts: The MIT Press.
2 Kaltenbrunner, A., Kellis, L. and Mart´, D. (n.d.). B-trees. [ebook] Available at:
http://www.di.ufpb.br/lucidio/Btrees.pdf [Accessed 25 Dec. 2017].
3 Koruga, P. and Bača, M. (n.d.). Analysis of B-tree data structure and its usage in
computer forensics. [ebook] p.4. Available at:
https://www.scribd.com/document/112071035/B-Tree-Application [Accessed 27
Dec. 2017].
27