(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
B TREE ( a to z concept ) in data structure or DBMS
1. INSTITUTE OF ENGINEERING AND TECHNOLOGY
OPERATIONS OF B TREEEE
NAME : HARSH MISHRA
ROLL NO. : 2214670010009
BRANCH : IT
DR. SURYABHAN PRATAP SINGH HOD(IT)
2. What is B-Tree?
A B-tree is a self-balancing tree where all the leaf nodes are at
the same level which allows for efficient searching, insertion
and deletion of records.
Because of all the leaf nodes being on the same level, the
access time of data is fixed regardless of the size of the data
set.
3. Characteristics of B-Tree
B-trees have several important characteristics that make them
useful for storing and retrieving large amounts of data
efficiently. Some of the key characteristics of B-trees are:
Balanced: B-trees are balanced, meaning that all leaf nodes are
at the same level. This ensures that the time required to access
data in the tree remains constant, regardless of the size of the
data set.
4. Self-balancing: B-trees are self-balancing, which means that
as new data is inserted or old data is deleted, the tree
automatically adjusts to maintain its balance.
Multiple keys per node: B-trees allow multiple keys to be
stored in each node. This allows for efficient use of memory
and reduces the height of the tree, which in turn reduces the
number of disk accesses required to retrieve data.
5. Ordered: B-trees maintain the order of the keys, which
makes searching and range queries efficient.
Efficient for large data sets: B-trees are particularly useful
for storing and retrieving large amounts of data, as they
minimize the number of disk accesses required to find a
particular piece of data.
6. Properties of B-Tree
1.All leaves are at the same level.
2.B-Tree is defined by the term minimum degree ‘t‘. The
value of ‘t‘ depends upon disk block size.
3.Every node except the root must contain at most t-1
keys. The root may contain a minimum of 1 key.
4.All nodes (including root) may contain at most (2*t – 1)
keys.
5.Number of children of a node is equal to the number of
keys in it plus 1.
7. 6.All keys of a node are sorted in increasing order. The child
between two keys k1 and k2 contains all keys in the range
from k1 and k2.
7.B-Tree grows and shrinks from the root which is unlike
Binary Search Tree. Binary Search Trees grow downward and
also shrink from downward.
8.Like other balanced Binary Search Trees, the time
complexity to search, insert and delete is O(log n).
9.Insertion of a Node in B-Tree happens only at Leaf Node.
9. 1.Searching
BtreeSearch(x, k)
i = 1
// n[x] means number of keys in x node
while i ≤ n[x] and k ≥ keyi[x]
do i = i + 1
if i n[x] and k = keyi[x]
then return (x, i)
if leaf [x]
then return NIL
else
return BtreeSearch(ci[x], k)
10. Searching in B Trees is similar to that in Binary search tree.
For example, if we search for an item 49 in the following B
Tree. The process will something like following :
->Compare item 49 with root node 78. since 49 < 78 hence,
move to its left sub-tree.
->Since, 40<49<56, traverse right sub-tree of 40.
->49>45, move to right. Compare 49.
->match found, return.
Example:
11.
12. 2.Inserting
1.Traverse the B Tree in order to find the appropriate leaf node at which the node
can be inserted.
2.If the leaf node contain less than m-1 keys then insert the element in the
increasing order.
3.Else, if the leaf node contains m-1 keys, then follow the following steps.
->Insert the new element in the increasing order of elements.
->Split the node into the two nodes at the median.
->Push the median element upto its parent node.
->If the parent node also contain m-1 number of keys, then split it too by
following the same steps.
14. 8 will be inserted to the right of 5, therefore insert 8.
15. The node, now contain 5 keys which is greater than (5 -1 = 4 ) keys.
Therefore split the node from the median i.e. 8 and push it up to its
parent node shown as follows.
16. 3.Deletion
1.Locate the leaf node.
2.If there are more than m/2 keys in the leaf node then delete the desired
key from the node.
3.If the leaf node doesn't contain m/2 keys then complete the keys by
taking the element from eight or left sibling.
->If the left sibling contains more than m/2 elements then push its largest
element up to its parent and move the intervening element down to the
node where the key is deleted.
->If the right sibling contains more than m/2 elements then push its
smallest element up to the parent and move intervening element down to
the node where the key is deleted.
17. NOTE : If the the node which is to be deleted is an internal node, then
replace the node with its in-order successor or predecessor. Since,
successor or predecessor will always be on the leaf node hence, the
process will be similar as the node is being deleted from the leaf node.
4.if neither of the sibling contain more than m/2 elements then
create a new leaf node by joining two leaf nodes and the intervening
element of the parent node.
5.If parent is left with less than m/2 nodes then, apply the above
process on the parent too.
19. 53 is present in the right child of element 49. Delete it.
20. Now, 57 is the only element which is left in the node, the minimum number of
elements that must be present in a B tree of order 5, is 2. it is less than that,
the elements in its left and right sub-tree are also not sufficient therefore,
merge it with the left sibling and intervening element of parent i.e. 49.
The final B tree is shown as follows.
21. Time Complexity of B-Tree
Sr. No. Algorithm Time Complexity
1. Search O(log n)
2. Insert O(log n)
3. Delete O(log n)
Note: “n” is the total number of elements in the B-tree
22. Applications of B-Tree
Databases: B-trees are widely used in databases to store
indexes that allow for efficient searching and retrieval of
data.
File systems: B-trees are used in file systems to organize and
store files efficiently.
Operating systems: B-trees are used in operating systems to
manage memory efficiently.
Network routers: B-trees are used in network routers to
efficiently route packets through the network.
23. DNS servers: B-trees are used in Domain Name System
(DNS) servers to store and retrieve information about
domain names.
Compiler symbol tables: B-trees are used in compilers to
store symbol tables that allow for efficient compilation of
code.
24. Advantages of B-Tree
Sequential Traversing: As the keys are kept in sorted
order, the tree can be traversed sequentially.
Minimize disk reads: It is a hierarchical structure and thus
minimizes disk reads.
Partially full blocks: The B-tree has partially full blocks
which speed up insertion and deletion.
25. Disadvantages of B-Tree
Not optimal for small data sets: B-trees are most effective
for storing and retrieving large amounts of data. For small
data sets, other data structures may be more efficient.
Limited branching factor: The branching factor of a B-tree
determines the number of child nodes that each node can
have. B-trees typically have a fixed branching factor, which
can limit their performance for certain types of data.