SlideShare a Scribd company logo
1 of 26
Download to read offline
INSTITUTE OF ENGINEERING AND TECHNOLOGY
OPERATIONS OF B TREEEE
NAME : HARSH MISHRA
ROLL NO. : 2214670010009
BRANCH : IT
DR. SURYABHAN PRATAP SINGH HOD(IT)
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.
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.
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.
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.
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.
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.
Operations of B Tree
1.Searching
2.Inserting
3.Deletion
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)
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:
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.
Example:
Insert the node 8 into the B Tree of order 5 shown in the
following image.
8 will be inserted to the right of 5, therefore insert 8.
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.
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.
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.
Example:
Delete the node 53 from the B Tree of order 5 shown in the following
figure.
53 is present in the right child of element 49. Delete it.
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.
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
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.
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.
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.
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.
THANK YOU

More Related Content

Similar to B TREE ( a to z concept ) in data structure or DBMS

Multiway Trees.ppt
Multiway Trees.pptMultiway Trees.ppt
Multiway Trees.pptAseemBhube1
 
Presentation on b trees [autosaved]
Presentation on b trees [autosaved]Presentation on b trees [autosaved]
Presentation on b trees [autosaved]AKASHKUMAR1542
 
chapter 6.1.pptx
chapter 6.1.pptxchapter 6.1.pptx
chapter 6.1.pptxTekle12
 
B-and-B-Tree-ppt presentation in data structure
B-and-B-Tree-ppt presentation in data structureB-and-B-Tree-ppt presentation in data structure
B-and-B-Tree-ppt presentation in data structuressuser19bb13
 
B trees and_b__trees
B trees and_b__treesB trees and_b__trees
B trees and_b__treesmeghu123
 
Unit-5 Advanced tree zxcppt
Unit-5 Advanced tree                     zxcpptUnit-5 Advanced tree                     zxcppt
Unit-5 Advanced tree zxcpptDhruvilSTATUS
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structureAnusruti Mitra
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Treesagar yadav
 
Best for b trees
Best for b treesBest for b trees
Best for b treesDineshRaaja
 
My File Structure Btrees Project Report
My File Structure Btrees Project ReportMy File Structure Btrees Project Report
My File Structure Btrees Project ReportUsman Sait
 
VCE Unit 05.pptx
VCE Unit 05.pptxVCE Unit 05.pptx
VCE Unit 05.pptxskilljiolms
 
Index Structures.pptx
Index Structures.pptxIndex Structures.pptx
Index Structures.pptxMBablu1
 

Similar to B TREE ( a to z concept ) in data structure or DBMS (20)

08 B Trees
08 B Trees08 B Trees
08 B Trees
 
Multiway Trees.ppt
Multiway Trees.pptMultiway Trees.ppt
Multiway Trees.ppt
 
Presentation on b trees [autosaved]
Presentation on b trees [autosaved]Presentation on b trees [autosaved]
Presentation on b trees [autosaved]
 
chapter 6.1.pptx
chapter 6.1.pptxchapter 6.1.pptx
chapter 6.1.pptx
 
B-and-B-Tree-ppt presentation in data structure
B-and-B-Tree-ppt presentation in data structureB-and-B-Tree-ppt presentation in data structure
B-and-B-Tree-ppt presentation in data structure
 
B trees and_b__trees
B trees and_b__treesB trees and_b__trees
B trees and_b__trees
 
Unit-5 Advanced tree zxcppt
Unit-5 Advanced tree                     zxcpptUnit-5 Advanced tree                     zxcppt
Unit-5 Advanced tree zxcppt
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structure
 
Indexing Data Structure
Indexing Data StructureIndexing Data Structure
Indexing Data Structure
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Best for b trees
Best for b treesBest for b trees
Best for b trees
 
My File Structure Btrees Project Report
My File Structure Btrees Project ReportMy File Structure Btrees Project Report
My File Structure Btrees Project Report
 
B trees dbms
B trees dbmsB trees dbms
B trees dbms
 
Makalah if2091-2011-020
Makalah if2091-2011-020Makalah if2091-2011-020
Makalah if2091-2011-020
 
B trees
B treesB trees
B trees
 
VCE Unit 05.pptx
VCE Unit 05.pptxVCE Unit 05.pptx
VCE Unit 05.pptx
 
DATASTORAGE.pdf
DATASTORAGE.pdfDATASTORAGE.pdf
DATASTORAGE.pdf
 
DATASTORAGE
DATASTORAGEDATASTORAGE
DATASTORAGE
 
Index Structures.pptx
Index Structures.pptxIndex Structures.pptx
Index Structures.pptx
 
Indexing.ppt
Indexing.pptIndexing.ppt
Indexing.ppt
 

Recently uploaded

UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 

Recently uploaded (20)

UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(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.
  • 8. Operations of B Tree 1.Searching 2.Inserting 3.Deletion
  • 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.
  • 13. Example: Insert the node 8 into the B Tree of order 5 shown in the following image.
  • 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.
  • 18. Example: Delete the node 53 from the B Tree of order 5 shown in the following figure.
  • 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.