PRESENTING YOU
TREES
• It’s an another n-ary Tree
• It actually is an optimization of B tree
• Contains root, internal nodes and leaf nodes like other Trees
• Internal nodes contains router value of data in leaves
• All data is stored at leaf level
• Leaf nodes are linked to each other
What actually is B+ Tree?
19
5 17 19 45
45
• Unlike B tree, B+ tree stores all the data on leaf level.
• They Maximize the branching factors (fanout)
• Higher branching factors allows less height
• Less height requires less disk I/O
• Which means better performance
WHY B+ Tree?
19
5 17 19 45
O(log š‘ š‘›)
• Every node has one more children than it has keys.
• All leaves are at the same distance from the root.
• If B+ tree has m order then
• Root: has between 2 and m children (or root could be a leaf).
• Internal Node: store up to m - 1 and have between āŽ”m/2āŽ¤ and m children.
• Leaf Nodes: where data is stored and all at the same depth, contain between
āŽ”L/2āŽ¤ and L data items.
• Order Property: subtree between two keys x and y contain leaves with values v
such that x ≤ v < y
Properties of B+ Tree
y
x v y v
• Insert at bottom level
• If leaf page (node) overflows, split page and copy middle element to
next index page
• If index page (node) overflows, split page and move middle element
to next index page
Insertion Rules
• Max Order (m): 3
• Insert 5
• Insert 45
• Insert 13
Let’s do some Insertion
5
13
Split
45
13
45 13 45
• Max Order (m): 3
• Insert 5
• Insert 45
• Insert 13
• Insert 23
Let’s do some Insertion
5 45
13
4513
23
Split
45
23
4523
• Max Order (m): 3
• Insert 5
• Insert 45
• Insert 13
• Insert 23
• Insert 32
Let’s do some Insertion
5 45
13
13
23
4523
32
Split
45
32
4532
• Max Order (m): 3
• Insert 5
• Insert 45
• Insert 13
• Insert 23
• Insert 32
Let’s do some Insertion
5 45
13
13
23
23
Split
45
32
4532
23
• Delete key and data from leaf page.
• If leaf page underflows, merge with sibling and delete key in between
them.
• If index page underflows, merge with sibling and move down key in
between them
Deletion Rules
• Delete 23
Let’s apply deletion on previous tree
5 45
13
13 23 45
32
4532
2332
45
45
32
• Delete 23
• Delete 13
Let’s apply deletion on previous tree
5
13
13 45
45
32
32
32
45
45
32
Cases Insertion Deletion Searching Space
Best Ī©(log š‘ š‘›) Ī©(log š‘ š‘›) Ī©(log š‘ š‘›) Ī©(š‘›)
Average Īø(log š‘ š‘›) Īø(log š‘ š‘›) Īø(log š‘ š‘›) Īø(š‘› + k)
Worst O(log š‘ š‘›) O(log š‘ š‘›) O(š‘. log š‘ š‘›) O(š‘› + k)
Complexities
Where b = order
n = number of keys in the tree
Comparison Analysis
Features B Tree B+ Tree
Storage
In a B tree, search keys and data
stored in internal or leaf nodes.
In a B+ tree, data stored only in leaf
nodes.
Function of leaf nodes
In B tree, the leaf node cannot
store using linked list.
In B+ tree, leaf node data are
ordered in a sequential linked list.
Search accessibility
Here in B tree the search is not that
easy as compared to a B+ tree.
Here in B+ tree the searching
becomes easy.
Redundant key
They do not store redundant search
key.
They store redundant search key.
Applications
B+ trees are used by
• NTFS, ReiserFS, NSS, XFS, JFS, ReFS, and BFS file systems for metadata
indexing
• BFS for storing directories.
• IBM DB2, Informix, Microsoft SQL Server, Oracle 8, Sybase ASE, and SQLite for
table indexes
Conclusion
B Tree
B+ Tree
It’s a Q/A time now