0% found this document useful (0 votes)
7 views17 pages

B Tree

B trees are m-way search trees that maintain sorted data and have a lower height compared to AVL and RB trees, making them efficient for disk access. They support operations like insertion, deletion, and searching, all with a time complexity of O(log n). The insertion and deletion processes involve managing keys and nodes to maintain the properties of the B tree, such as ensuring all leaf nodes are at the same level and adhering to minimum and maximum key constraints.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views17 pages

B Tree

B trees are m-way search trees that maintain sorted data and have a lower height compared to AVL and RB trees, making them efficient for disk access. They support operations like insertion, deletion, and searching, all with a time complexity of O(log n). The insertion and deletion processes involve managing keys and nodes to maintain the properties of the B tree, such as ensuring all leaf nodes are at the same level and adhering to minimum and maximum key constraints.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

B Tree

B trees are extended binary search trees that are specialized in m-way searching, since the order of B trees is 'm'.
Order of a tree is defined as the maximum number of children a node can accommodate. Therefore, the height of a
b tree is relatively smaller than the height of AVL tree and RB tree.

They are general form of a Binary Search Tree as it holds more than one key and two children.

The various properties of B trees include −

• Every node in a B Tree will hold a maximum of m children and (m-1) keys, since the order of the tree is m.
• Every node in a B tree, except root and leaf, can hold at least m/2 children
• The root node must have no less than two children.
• All the paths in a B tree must end at the same level, i.e. the leaf nodes must be at the same level.
• A B tree always maintains sorted data.

B trees are also widely used in disk access, minimizing the disk access time since the height of a b tree is low.
Note − A disk access is the memory access to the computer disk where the information is stored and disk access
time is the time taken by the system to access the disk memory.

Basic Operations of B Trees


The operations supported in B trees are Insertion, deletion and searching with the time complexity of O(log n) for
every operation.

Insertion operation
The insertion operation for a B Tree is done similar to the Binary Search Tree but the elements are inserted into the
same node until the maximum keys are reached. The insertion is done using the following procedure −
𝑚
Step 1 − Calculate the maximum (𝑚 − 1) and, minimum (⌈ ⌉ − 1) number of keys a node can hold, where m is
2
denoted by the order of the B Tree.
Step 2 − The data is inserted into the tree using the binary search insertion and once the keys reach the maximum
number, the node is split into half and the median key becomes the internal node while the left and right keys
become its children.
Step 3 − All the leaf nodes must be on the same level.
The keys, 5, 3, 21, 9, 13 are all added into the node according to the binary search property but if we add the key
22, it will violate the maximum key property. Hence, the node is split in half, the median key is shifted to the parent
node and the insertion is then continued.
Another hiccup occurs during the insertion of 11, so the node is split and median is shifted to the parent.
While inserting 16, even if the node is split in two parts, the parent node also overflows as it reached the maximum
keys. Hence, the parent node is split first and the median key becomes the root. Then, the leaf node is split in half
the median of leaf node is shifted to its parent.
16

21

The final B tree after inserting all the elements is achieved.


Deletion operation
The deletion operation in a B tree is slightly different from the deletion operation of a Binary Search Tree. The
procedure to delete a node from a B tree is as follows −

Case 1 − If the key to be deleted is in a leaf node and the deletion does not violate the minimum key property, just
delete the node.
Case 2 − If the key to be deleted is in a leaf node but the deletion violates the minimum key property, borrow a
key from either its left sibling or right sibling. In case if both siblings have exact minimum number of keys, merge
the node in either of them.
Case 3 − If the key to be deleted is in an internal node, it is replaced by a key in either left child or right child
based on which child has more keys. But if both child nodes have minimum number of keys, they’re merged
together.
Case 4 − If the key to be deleted is in an internal node violating the minimum keys property, and both its children
and sibling have minimum number of keys, merge the children. Then merge its sibling with its parent.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy