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

Presentation on b trees [autosaved]
Presentation on b trees [autosaved]Presentation on b trees [autosaved]
Presentation on b trees [autosaved]
AKASHKUMAR1542
 
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
ssuser19bb13
 
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmmIndexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
RAtna29
 

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 mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmmIndexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
 

Recently uploaded

一比一原版(UNK毕业证)内布拉斯加州立大学科尼分校毕业证成绩单
一比一原版(UNK毕业证)内布拉斯加州立大学科尼分校毕业证成绩单一比一原版(UNK毕业证)内布拉斯加州立大学科尼分校毕业证成绩单
一比一原版(UNK毕业证)内布拉斯加州立大学科尼分校毕业证成绩单
tuuww
 
Laundry management system project report.pdf
Laundry management system project report.pdfLaundry management system project report.pdf
Laundry management system project report.pdf
Kamal Acharya
 
School management system project report.pdf
School management system project report.pdfSchool management system project report.pdf
School management system project report.pdf
Kamal Acharya
 

Recently uploaded (20)

"United Nations Park" Site Visit Report.
"United Nations Park" Site  Visit Report."United Nations Park" Site  Visit Report.
"United Nations Park" Site Visit Report.
 
Supermarket billing system project report..pdf
Supermarket billing system project report..pdfSupermarket billing system project report..pdf
Supermarket billing system project report..pdf
 
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical EngineeringIntroduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
 
An improvement in the safety of big data using blockchain technology
An improvement in the safety of big data using blockchain technologyAn improvement in the safety of big data using blockchain technology
An improvement in the safety of big data using blockchain technology
 
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdfA CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
 
Furniture showroom management system project.pdf
Furniture showroom management system project.pdfFurniture showroom management system project.pdf
Furniture showroom management system project.pdf
 
Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1
 
Low rpm Generator for efficient energy harnessing from a two stage wind turbine
Low rpm Generator for efficient energy harnessing from a two stage wind turbineLow rpm Generator for efficient energy harnessing from a two stage wind turbine
Low rpm Generator for efficient energy harnessing from a two stage wind turbine
 
Natalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in KrakówNatalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in Kraków
 
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdfRESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
 
İTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering WorkshopİTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering Workshop
 
一比一原版(UNK毕业证)内布拉斯加州立大学科尼分校毕业证成绩单
一比一原版(UNK毕业证)内布拉斯加州立大学科尼分校毕业证成绩单一比一原版(UNK毕业证)内布拉斯加州立大学科尼分校毕业证成绩单
一比一原版(UNK毕业证)内布拉斯加州立大学科尼分校毕业证成绩单
 
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptxCloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
 
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and VisualizationKIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
 
Laundry management system project report.pdf
Laundry management system project report.pdfLaundry management system project report.pdf
Laundry management system project report.pdf
 
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
 
internship exam ppt.pptx on embedded system and IOT
internship exam ppt.pptx on embedded system and IOTinternship exam ppt.pptx on embedded system and IOT
internship exam ppt.pptx on embedded system and IOT
 
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWINGBRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
 
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
 
School management system project report.pdf
School management system project report.pdfSchool management system project report.pdf
School management system project report.pdf
 

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.