SlideShare una empresa de Scribd logo
1 de 36
B+ Tree
• In order, to implement dynamic multilevel indexing, B-tree and B+ tree are generally employed. The drawback
of B-tree used for indexing, however is that it stores the data pointer (a pointer to the disk file block containing
the key value), corresponding to a particular key value, along with that key value in the node of a B-tree. This
technique, greatly reduces the number of entries that can be packed into a node of a B-tree, thereby
contributing to the increase in the number of levels in the B-tree, hence increasing the search time of a record
• B+ tree eliminates the above drawback by storing data pointers only at the leaf nodes of the tree. Thus, the
structure of leaf nodes of a B+ tree is quite different from the structure of internal nodes of the B tree. It may
be noted here that, since data pointers are present only at the leaf nodes, the leaf nodes must necessarily store
all the key values along with their corresponding data pointers to the disk file block, in order to access them.
Moreover, the leaf nodes are linked to provide ordered access to the records. The leaf nodes, therefore form the
first level of index, with the internal nodes forming the other levels of a multilevel index. Some of the key
values of the leaf nodes also appear in the internal nodes, to simply act as a medium to control the searching of
a record.
• From the above discussion it is apparent that a B+ tree, unlike a B-tree has two orders, ‘a’ and ‘b’, one for the
internal nodes and the other for the external (or leaf) nodes.
Order 4
• Max no keys a node can hold :- (m-1) = 3
• Max no children's a node can have :-(m) 4
• Min Numb of keys a node can hold :- c(m/2) -1 =
• Min no child :- m/2 = 4
A B+ tree is an advanced form of a self-balancing tree in which all the values are present in the leaf level.
An important concept to be understood before learning B+ tree is multilevel indexing. In multilevel indexing,
the index of indices is created as in figure below. It makes accessing the data easier and faster.
• Properties of a B+ Tree
1.All leaves are at the same level.
2.The root has at least two children.
3.Each node except root can have a maximum of m children and at least m/2 children.
4.Each node can contain a maximum of m - 1 keys and a minimum of c⌈m/2⌉ - 1 keys.
Comparison between a B-tree and a B+ Tree
Diagram-II
Using the Pnext pointer it is viable to traverse all the leaf nodes, just like a linked list, thereby
achieving ordered access to the records stored in the disk.
A Diagram of B+ Tree
Advantage –
1. Records can be fetched in equal number of disk accesses.
2. Height of the tree remains balanced and less as compare to B tree.
3. We can access the data stored in a B+ tree sequentially as well as directly.
4. Keys are used for indexing.
5. Faster search queries as the data is stored only on the leaf nodes.
Let’s see the difference between B-tree and B+ tree:
S.NO B tree B+ tree
1.
All internal and leaf nodes have data
pointers
Only leaf nodes have data pointers
2.
Since all keys are not available at leaf,
search often takes more time.
All keys are at leaf nodes, hence search is
faster and accurate..
3.
No duplicate of keys is maintained in the
tree.
Duplicate of keys are maintained and all
nodes are present at leaf.
4.
Insertion takes more time and it is not
predictable sometimes.
Insertion is easier and the results are always
the same.
5.
Deletion of internal node is very complex
and tree has to undergo lot of
transformations.
Deletion of any node is easy because all
node are found at leaf.
6.
Leaf nodes are not stored as structural
linked list.
Leaf nodes are stored as structural linked
list.
7. No redundant search keys are present.. Redundant search keys may be present..
B tree and B+ tree
Searching on a B+ Tree
• The following steps are followed to search for data in a B+ Tree of order m. Let
the data to be searched be k.
• Start from the root node. Compare k with the keys at the root node [k1, k2,
k3,......km - 1].
• If k < k1, go to the left child of the root node.
• Else if k > k1, compare k2. If k < k2, k lies between k1 and k2. So, search in the
left child of k2.
• If k > k2, go for k3, k4,...km-1 as in steps 2 and 3.
• Repeat the above steps until a leaf node is reached.
• If k exists in the leaf node, return true else return false.
Searching Example on a B+ Tree
Let us search k = 45 on the following B+ tree.
Compare k(k=45) with the root node.
5,15, 25, 35, 45. m =3 max key = 2
•
• 25
• 15 35
• 5 15 25 35,45
1,4,7,10,17 m = 3 2
• 7
• 4 10
• 1 4 7 10,17
1,4,7,10,17,21,31,25 order = 4 key = 3
1,4,7,10,17,21,31,25,19,20,28,48
right bias
root elem = 20
Internal node = 7,17 25,31
Leaf node = 1,4 7,10 17,19 20,21 25,28 31,48
Keys = 7,10,1,23,5, 15, 17, 9, 11, 39,35, 8, 40,25
m = 5 max key = 4
• 15
• 7 9 23 35
• 1,5 7,8 9,10,11 15,17 23,25 35,39,40
Since k > 25, go to the right child
Compare k with 35. Since k > 35, compare k with 45.
Since k ≥ 45, so go to the right child.
k is found
Inserting an element into a B+ tree consists of two main events: searching the appropriate leaf to inserting the
element and balancing/splitting the tree.
Insertion Operation
• Before inserting an element into a B+ tree, these properties must be kept in mind.
• The root has at least two children(b and b+ tree are generalized form of BST).
• Each node except root can have a maximum of m children and at least m/2 children.
• Each node can contain a maximum of m - 1 keys and a minimum of ⌈- 1 keys.
• The following steps are followed for inserting an element.
1. Since every element is inserted into the leaf node, go to the appropriate leaf node.
2. Insert the key into the leaf node.
• Case I
1. If the leaf is not full, insert the key into the leaf node in increasing order.
• Case II
1. If the leaf is full, insert the key into the leaf node in increasing order and balance the tree in the following way.
2. Break the node at m/2th position(median).
3. Add m/2th key to the parent node as well.
4. If the parent node is already full, follow steps 2 to 3.
Insertion Example
Let us understand the insertion operation with the illustrations below.
The elements to be inserted are 5,15, 25, 35, 45.
1. Insert 5.
2. Insert 15.
Insert 25
The elements to be inserted are 5,15, 25, 35, 45.
Insert 35.
The elements to be inserted are 5,15, 25, 35, 45.
Insert 45
The elements to be inserted are 5,15, 25, 35, 45.
Deletion from a B+ Tree
Deleting an element on a B+ tree consists of three main events: searching the node where the key to be deleted
exists, deleting the key and balancing the tree if required. Underflow is a situation when there is less number of
keys in a node than the minimum number of keys it should hold.
• Deletion Operation
• Before going through the steps below, one must know these facts about a B+ tree
of degree m(m=3).
• A node can have a maximum of m children. (i.e. 3)
• A node can contain a maximum of m - 1 keys. (i.e. 2)
• A node should have a minimum of ⌈m/2⌉ children. (i.e. 2)
• A node (except root node) should contain a minimum of ⌈m/2⌉ - 1 keys. (i.e. 1)
• While deleting a key, we have to take care of the keys present in the internal nodes
(i.e. indexes) as well because the values are redundant in a B+ tree. Search the key
to be deleted then follow the following steps.
Case I
The key to be deleted is present only at the leaf node not in the indexes (or internal nodes). There are
two cases for it:
1.There is more than the minimum number of keys in the node. Simply delete the key.
2) There is an exact minimum number of keys in the node. Delete the key and borrow a key from the
immediate sibling. Add the median key of the sibling node to the parent.
Case II
The key to be deleted is present in the internal nodes as well. Then we have to remove them from the internal
nodes as well. There are the following cases for this situation.
1) If there is more than the minimum number of keys in the node, simply delete the key from the leaf node and
delete the key from the internal node as well.
Fill the empty space in the internal node with the inorder successor.
2) If there is an exact minimum number of keys in the node, then delete the key and
borrow a key from its immediate sibling (through the parent).
Fill the empty space created in the index (internal node) with the borrowed key.
3) This case is similar to Case II(1) but here, empty space is generated above the
immediate parent node.
After deleting the key, merge the empty space with its sibling.
Fill the empty space in the grandparent node with the inorder successor.
Case III
In this case, the height of the tree gets shrinked. It is a little complicated. Deleting 55 from the tree
below leads to this condition. It can be understood in the illustrations below.
B+ Tree Applications
• Multilevel Indexing
• Faster operations on the tree (insertion, deletion, search)
• Database indexing

Más contenido relacionado

La actualidad más candente

BOOTH ALGO, DIVISION(RESTORING _ NON RESTORING) etc etc
BOOTH ALGO, DIVISION(RESTORING _ NON RESTORING) etc etcBOOTH ALGO, DIVISION(RESTORING _ NON RESTORING) etc etc
BOOTH ALGO, DIVISION(RESTORING _ NON RESTORING) etc etcAbhishek Rajpoot
 
Multivalued dependency
Multivalued dependencyMultivalued dependency
Multivalued dependencyavniS
 
12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMSkoolkampus
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy methodhodcsencet
 
Previous question papers of Database Management System (DBMS) By SHABEEB
Previous question papers of Database Management System (DBMS) By SHABEEBPrevious question papers of Database Management System (DBMS) By SHABEEB
Previous question papers of Database Management System (DBMS) By SHABEEBShabeeb Shabi
 
Chapter-7 Relational Calculus
Chapter-7 Relational CalculusChapter-7 Relational Calculus
Chapter-7 Relational CalculusKunal Anand
 
Data science life cycle
Data science life cycleData science life cycle
Data science life cycleManoj Mishra
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data StructureMeghaj Mallick
 
Database design & Normalization (1NF, 2NF, 3NF)
Database design & Normalization (1NF, 2NF, 3NF)Database design & Normalization (1NF, 2NF, 3NF)
Database design & Normalization (1NF, 2NF, 3NF)Jargalsaikhan Alyeksandr
 
Mapping cardinalities
Mapping cardinalitiesMapping cardinalities
Mapping cardinalitiesArafat Hossan
 
Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}FellowBuddy.com
 
01 c++ Intro.ppt
01 c++ Intro.ppt01 c++ Intro.ppt
01 c++ Intro.pptTareq Hasan
 

La actualidad más candente (20)

BOOTH ALGO, DIVISION(RESTORING _ NON RESTORING) etc etc
BOOTH ALGO, DIVISION(RESTORING _ NON RESTORING) etc etcBOOTH ALGO, DIVISION(RESTORING _ NON RESTORING) etc etc
BOOTH ALGO, DIVISION(RESTORING _ NON RESTORING) etc etc
 
Multivalued dependency
Multivalued dependencyMultivalued dependency
Multivalued dependency
 
12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
 
AVL Tree in Data Structure
AVL Tree in Data Structure AVL Tree in Data Structure
AVL Tree in Data Structure
 
Complements
ComplementsComplements
Complements
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
Hashing
HashingHashing
Hashing
 
Previous question papers of Database Management System (DBMS) By SHABEEB
Previous question papers of Database Management System (DBMS) By SHABEEBPrevious question papers of Database Management System (DBMS) By SHABEEB
Previous question papers of Database Management System (DBMS) By SHABEEB
 
Chapter-7 Relational Calculus
Chapter-7 Relational CalculusChapter-7 Relational Calculus
Chapter-7 Relational Calculus
 
Data science life cycle
Data science life cycleData science life cycle
Data science life cycle
 
Np cooks theorem
Np cooks theoremNp cooks theorem
Np cooks theorem
 
Binary trees1
Binary trees1Binary trees1
Binary trees1
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
Database design & Normalization (1NF, 2NF, 3NF)
Database design & Normalization (1NF, 2NF, 3NF)Database design & Normalization (1NF, 2NF, 3NF)
Database design & Normalization (1NF, 2NF, 3NF)
 
B and B+ tree
B and B+ treeB and B+ tree
B and B+ tree
 
Mapping cardinalities
Mapping cardinalitiesMapping cardinalities
Mapping cardinalities
 
Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}
 
01 c++ Intro.ppt
01 c++ Intro.ppt01 c++ Intro.ppt
01 c++ Intro.ppt
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 

Similar a B+ tree.pptx

Data structures trees - B Tree & B+Tree.pptx
Data structures trees - B Tree & B+Tree.pptxData structures trees - B Tree & B+Tree.pptx
Data structures trees - B Tree & B+Tree.pptxMalligaarjunanN
 
B TREE ( a to z concept ) in data structure or DBMS
B TREE ( a to z concept ) in data structure  or DBMSB TREE ( a to z concept ) in data structure  or DBMS
B TREE ( a to z concept ) in data structure or DBMSMathkeBhoot
 
Furnish an Index Using the Works of Tree Structures
Furnish an Index Using the Works of Tree StructuresFurnish an Index Using the Works of Tree Structures
Furnish an Index Using the Works of Tree Structuresijceronline
 
Multiway Trees.ppt
Multiway Trees.pptMultiway Trees.ppt
Multiway Trees.pptAseemBhube1
 
Unit-5 Advanced tree zxcppt
Unit-5 Advanced tree                     zxcpptUnit-5 Advanced tree                     zxcppt
Unit-5 Advanced tree zxcpptDhruvilSTATUS
 
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
 
VCE Unit 05.pptx
VCE Unit 05.pptxVCE Unit 05.pptx
VCE Unit 05.pptxskilljiolms
 
chapter 6.1.pptx
chapter 6.1.pptxchapter 6.1.pptx
chapter 6.1.pptxTekle12
 
109885098-B-Trees-And-B-Trees in data structure.ppt
109885098-B-Trees-And-B-Trees in data structure.ppt109885098-B-Trees-And-B-Trees in data structure.ppt
109885098-B-Trees-And-B-Trees in data structure.pptssuser19bb13
 
btrees.ppt ttttttttttttttttttttttttttttt
btrees.ppt  tttttttttttttttttttttttttttttbtrees.ppt  ttttttttttttttttttttttttttttt
btrees.ppt tttttttttttttttttttttttttttttRAtna29
 
BTrees-fall2010.ppt
BTrees-fall2010.pptBTrees-fall2010.ppt
BTrees-fall2010.pptzalanmvb
 

Similar a B+ tree.pptx (20)

Data structures trees - B Tree & B+Tree.pptx
Data structures trees - B Tree & B+Tree.pptxData structures trees - B Tree & B+Tree.pptx
Data structures trees - B Tree & B+Tree.pptx
 
B TREE ( a to z concept ) in data structure or DBMS
B TREE ( a to z concept ) in data structure  or DBMSB TREE ( a to z concept ) in data structure  or DBMS
B TREE ( a to z concept ) in data structure or DBMS
 
A41001011
A41001011A41001011
A41001011
 
Furnish an Index Using the Works of Tree Structures
Furnish an Index Using the Works of Tree StructuresFurnish an Index Using the Works of Tree Structures
Furnish an Index Using the Works of Tree Structures
 
Jamal ppt b+tree dbms
Jamal ppt b+tree dbmsJamal ppt b+tree dbms
Jamal ppt b+tree dbms
 
Multiway Trees.ppt
Multiway Trees.pptMultiway Trees.ppt
Multiway Trees.ppt
 
Unit-5 Advanced tree zxcppt
Unit-5 Advanced tree                     zxcpptUnit-5 Advanced tree                     zxcppt
Unit-5 Advanced tree zxcppt
 
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
 
08 B Trees
08 B Trees08 B Trees
08 B Trees
 
VCE Unit 05.pptx
VCE Unit 05.pptxVCE Unit 05.pptx
VCE Unit 05.pptx
 
chapter 6.1.pptx
chapter 6.1.pptxchapter 6.1.pptx
chapter 6.1.pptx
 
B trees
B treesB trees
B trees
 
B trees dbms
B trees dbmsB trees dbms
B trees dbms
 
109885098-B-Trees-And-B-Trees in data structure.ppt
109885098-B-Trees-And-B-Trees in data structure.ppt109885098-B-Trees-And-B-Trees in data structure.ppt
109885098-B-Trees-And-B-Trees in data structure.ppt
 
Makalah if2091-2011-020
Makalah if2091-2011-020Makalah if2091-2011-020
Makalah if2091-2011-020
 
B tree
B  treeB  tree
B tree
 
Btree
BtreeBtree
Btree
 
btrees.ppt ttttttttttttttttttttttttttttt
btrees.ppt  tttttttttttttttttttttttttttttbtrees.ppt  ttttttttttttttttttttttttttttt
btrees.ppt ttttttttttttttttttttttttttttt
 
BTrees-fall2010.ppt
BTrees-fall2010.pptBTrees-fall2010.ppt
BTrees-fall2010.ppt
 

Último

Secure Key Crypto - Tech Paper JET Tech Labs
Secure Key Crypto - Tech Paper JET Tech LabsSecure Key Crypto - Tech Paper JET Tech Labs
Secure Key Crypto - Tech Paper JET Tech Labsamber724300
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxRomil Mishra
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating SystemRashmi Bhat
 
Energy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxEnergy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxsiddharthjain2303
 
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...Sumanth A
 
CS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdfCS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdfBalamuruganV28
 
Javier_Fernandez_CARS_workshop_presentation.pptx
Javier_Fernandez_CARS_workshop_presentation.pptxJavier_Fernandez_CARS_workshop_presentation.pptx
Javier_Fernandez_CARS_workshop_presentation.pptxJavier Fernández Muñoz
 
Python Programming for basic beginners.pptx
Python Programming for basic beginners.pptxPython Programming for basic beginners.pptx
Python Programming for basic beginners.pptxmohitesoham12
 
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.ppt
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.pptROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.ppt
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.pptJohnWilliam111370
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating SystemRashmi Bhat
 
11. Properties of Liquid Fuels in Energy Engineering.pdf
11. Properties of Liquid Fuels in Energy Engineering.pdf11. Properties of Liquid Fuels in Energy Engineering.pdf
11. Properties of Liquid Fuels in Energy Engineering.pdfHafizMudaserAhmad
 
Prach: A Feature-Rich Platform Empowering the Autism Community
Prach: A Feature-Rich Platform Empowering the Autism CommunityPrach: A Feature-Rich Platform Empowering the Autism Community
Prach: A Feature-Rich Platform Empowering the Autism Communityprachaibot
 
A brief look at visionOS - How to develop app on Apple's Vision Pro
A brief look at visionOS - How to develop app on Apple's Vision ProA brief look at visionOS - How to develop app on Apple's Vision Pro
A brief look at visionOS - How to develop app on Apple's Vision ProRay Yuan Liu
 
Levelling - Rise and fall - Height of instrument method
Levelling - Rise and fall - Height of instrument methodLevelling - Rise and fall - Height of instrument method
Levelling - Rise and fall - Height of instrument methodManicka Mamallan Andavar
 
Novel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending ActuatorsNovel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending ActuatorsResearcher Researcher
 
DEVICE DRIVERS AND INTERRUPTS SERVICE MECHANISM.pdf
DEVICE DRIVERS AND INTERRUPTS  SERVICE MECHANISM.pdfDEVICE DRIVERS AND INTERRUPTS  SERVICE MECHANISM.pdf
DEVICE DRIVERS AND INTERRUPTS SERVICE MECHANISM.pdfAkritiPradhan2
 
Artificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewArtificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewsandhya757531
 
SOFTWARE ESTIMATION COCOMO AND FP CALCULATION
SOFTWARE ESTIMATION COCOMO AND FP CALCULATIONSOFTWARE ESTIMATION COCOMO AND FP CALCULATION
SOFTWARE ESTIMATION COCOMO AND FP CALCULATIONSneha Padhiar
 
Comprehensive energy systems.pdf Comprehensive energy systems.pdf
Comprehensive energy systems.pdf Comprehensive energy systems.pdfComprehensive energy systems.pdf Comprehensive energy systems.pdf
Comprehensive energy systems.pdf Comprehensive energy systems.pdfalene1
 
Immutable Image-Based Operating Systems - EW2024.pdf
Immutable Image-Based Operating Systems - EW2024.pdfImmutable Image-Based Operating Systems - EW2024.pdf
Immutable Image-Based Operating Systems - EW2024.pdfDrew Moseley
 

Último (20)

Secure Key Crypto - Tech Paper JET Tech Labs
Secure Key Crypto - Tech Paper JET Tech LabsSecure Key Crypto - Tech Paper JET Tech Labs
Secure Key Crypto - Tech Paper JET Tech Labs
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptx
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating System
 
Energy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxEnergy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptx
 
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
 
CS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdfCS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdf
 
Javier_Fernandez_CARS_workshop_presentation.pptx
Javier_Fernandez_CARS_workshop_presentation.pptxJavier_Fernandez_CARS_workshop_presentation.pptx
Javier_Fernandez_CARS_workshop_presentation.pptx
 
Python Programming for basic beginners.pptx
Python Programming for basic beginners.pptxPython Programming for basic beginners.pptx
Python Programming for basic beginners.pptx
 
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.ppt
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.pptROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.ppt
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.ppt
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating System
 
11. Properties of Liquid Fuels in Energy Engineering.pdf
11. Properties of Liquid Fuels in Energy Engineering.pdf11. Properties of Liquid Fuels in Energy Engineering.pdf
11. Properties of Liquid Fuels in Energy Engineering.pdf
 
Prach: A Feature-Rich Platform Empowering the Autism Community
Prach: A Feature-Rich Platform Empowering the Autism CommunityPrach: A Feature-Rich Platform Empowering the Autism Community
Prach: A Feature-Rich Platform Empowering the Autism Community
 
A brief look at visionOS - How to develop app on Apple's Vision Pro
A brief look at visionOS - How to develop app on Apple's Vision ProA brief look at visionOS - How to develop app on Apple's Vision Pro
A brief look at visionOS - How to develop app on Apple's Vision Pro
 
Levelling - Rise and fall - Height of instrument method
Levelling - Rise and fall - Height of instrument methodLevelling - Rise and fall - Height of instrument method
Levelling - Rise and fall - Height of instrument method
 
Novel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending ActuatorsNovel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending Actuators
 
DEVICE DRIVERS AND INTERRUPTS SERVICE MECHANISM.pdf
DEVICE DRIVERS AND INTERRUPTS  SERVICE MECHANISM.pdfDEVICE DRIVERS AND INTERRUPTS  SERVICE MECHANISM.pdf
DEVICE DRIVERS AND INTERRUPTS SERVICE MECHANISM.pdf
 
Artificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewArtificial Intelligence in Power System overview
Artificial Intelligence in Power System overview
 
SOFTWARE ESTIMATION COCOMO AND FP CALCULATION
SOFTWARE ESTIMATION COCOMO AND FP CALCULATIONSOFTWARE ESTIMATION COCOMO AND FP CALCULATION
SOFTWARE ESTIMATION COCOMO AND FP CALCULATION
 
Comprehensive energy systems.pdf Comprehensive energy systems.pdf
Comprehensive energy systems.pdf Comprehensive energy systems.pdfComprehensive energy systems.pdf Comprehensive energy systems.pdf
Comprehensive energy systems.pdf Comprehensive energy systems.pdf
 
Immutable Image-Based Operating Systems - EW2024.pdf
Immutable Image-Based Operating Systems - EW2024.pdfImmutable Image-Based Operating Systems - EW2024.pdf
Immutable Image-Based Operating Systems - EW2024.pdf
 

B+ tree.pptx

  • 1. B+ Tree • In order, to implement dynamic multilevel indexing, B-tree and B+ tree are generally employed. The drawback of B-tree used for indexing, however is that it stores the data pointer (a pointer to the disk file block containing the key value), corresponding to a particular key value, along with that key value in the node of a B-tree. This technique, greatly reduces the number of entries that can be packed into a node of a B-tree, thereby contributing to the increase in the number of levels in the B-tree, hence increasing the search time of a record • B+ tree eliminates the above drawback by storing data pointers only at the leaf nodes of the tree. Thus, the structure of leaf nodes of a B+ tree is quite different from the structure of internal nodes of the B tree. It may be noted here that, since data pointers are present only at the leaf nodes, the leaf nodes must necessarily store all the key values along with their corresponding data pointers to the disk file block, in order to access them. Moreover, the leaf nodes are linked to provide ordered access to the records. The leaf nodes, therefore form the first level of index, with the internal nodes forming the other levels of a multilevel index. Some of the key values of the leaf nodes also appear in the internal nodes, to simply act as a medium to control the searching of a record. • From the above discussion it is apparent that a B+ tree, unlike a B-tree has two orders, ‘a’ and ‘b’, one for the internal nodes and the other for the external (or leaf) nodes.
  • 2. Order 4 • Max no keys a node can hold :- (m-1) = 3 • Max no children's a node can have :-(m) 4 • Min Numb of keys a node can hold :- c(m/2) -1 = • Min no child :- m/2 = 4
  • 3. A B+ tree is an advanced form of a self-balancing tree in which all the values are present in the leaf level. An important concept to be understood before learning B+ tree is multilevel indexing. In multilevel indexing, the index of indices is created as in figure below. It makes accessing the data easier and faster.
  • 4. • Properties of a B+ Tree 1.All leaves are at the same level. 2.The root has at least two children. 3.Each node except root can have a maximum of m children and at least m/2 children. 4.Each node can contain a maximum of m - 1 keys and a minimum of c⌈m/2⌉ - 1 keys.
  • 5. Comparison between a B-tree and a B+ Tree
  • 6. Diagram-II Using the Pnext pointer it is viable to traverse all the leaf nodes, just like a linked list, thereby achieving ordered access to the records stored in the disk.
  • 7. A Diagram of B+ Tree
  • 8. Advantage – 1. Records can be fetched in equal number of disk accesses. 2. Height of the tree remains balanced and less as compare to B tree. 3. We can access the data stored in a B+ tree sequentially as well as directly. 4. Keys are used for indexing. 5. Faster search queries as the data is stored only on the leaf nodes.
  • 9.
  • 10. Let’s see the difference between B-tree and B+ tree: S.NO B tree B+ tree 1. All internal and leaf nodes have data pointers Only leaf nodes have data pointers 2. Since all keys are not available at leaf, search often takes more time. All keys are at leaf nodes, hence search is faster and accurate.. 3. No duplicate of keys is maintained in the tree. Duplicate of keys are maintained and all nodes are present at leaf. 4. Insertion takes more time and it is not predictable sometimes. Insertion is easier and the results are always the same. 5. Deletion of internal node is very complex and tree has to undergo lot of transformations. Deletion of any node is easy because all node are found at leaf. 6. Leaf nodes are not stored as structural linked list. Leaf nodes are stored as structural linked list. 7. No redundant search keys are present.. Redundant search keys may be present..
  • 11. B tree and B+ tree
  • 12. Searching on a B+ Tree • The following steps are followed to search for data in a B+ Tree of order m. Let the data to be searched be k. • Start from the root node. Compare k with the keys at the root node [k1, k2, k3,......km - 1]. • If k < k1, go to the left child of the root node. • Else if k > k1, compare k2. If k < k2, k lies between k1 and k2. So, search in the left child of k2. • If k > k2, go for k3, k4,...km-1 as in steps 2 and 3. • Repeat the above steps until a leaf node is reached. • If k exists in the leaf node, return true else return false.
  • 13. Searching Example on a B+ Tree Let us search k = 45 on the following B+ tree.
  • 14. Compare k(k=45) with the root node.
  • 15.
  • 16. 5,15, 25, 35, 45. m =3 max key = 2 • • 25 • 15 35 • 5 15 25 35,45
  • 17. 1,4,7,10,17 m = 3 2 • 7 • 4 10 • 1 4 7 10,17
  • 18. 1,4,7,10,17,21,31,25 order = 4 key = 3 1,4,7,10,17,21,31,25,19,20,28,48 right bias root elem = 20 Internal node = 7,17 25,31 Leaf node = 1,4 7,10 17,19 20,21 25,28 31,48
  • 19. Keys = 7,10,1,23,5, 15, 17, 9, 11, 39,35, 8, 40,25 m = 5 max key = 4 • 15 • 7 9 23 35 • 1,5 7,8 9,10,11 15,17 23,25 35,39,40
  • 20. Since k > 25, go to the right child
  • 21. Compare k with 35. Since k > 35, compare k with 45.
  • 22. Since k ≥ 45, so go to the right child.
  • 24. Inserting an element into a B+ tree consists of two main events: searching the appropriate leaf to inserting the element and balancing/splitting the tree. Insertion Operation • Before inserting an element into a B+ tree, these properties must be kept in mind. • The root has at least two children(b and b+ tree are generalized form of BST). • Each node except root can have a maximum of m children and at least m/2 children. • Each node can contain a maximum of m - 1 keys and a minimum of ⌈- 1 keys. • The following steps are followed for inserting an element. 1. Since every element is inserted into the leaf node, go to the appropriate leaf node. 2. Insert the key into the leaf node. • Case I 1. If the leaf is not full, insert the key into the leaf node in increasing order. • Case II 1. If the leaf is full, insert the key into the leaf node in increasing order and balance the tree in the following way. 2. Break the node at m/2th position(median). 3. Add m/2th key to the parent node as well. 4. If the parent node is already full, follow steps 2 to 3.
  • 25. Insertion Example Let us understand the insertion operation with the illustrations below. The elements to be inserted are 5,15, 25, 35, 45. 1. Insert 5. 2. Insert 15.
  • 26. Insert 25 The elements to be inserted are 5,15, 25, 35, 45.
  • 27. Insert 35. The elements to be inserted are 5,15, 25, 35, 45.
  • 28. Insert 45 The elements to be inserted are 5,15, 25, 35, 45.
  • 29. Deletion from a B+ Tree Deleting an element on a B+ tree consists of three main events: searching the node where the key to be deleted exists, deleting the key and balancing the tree if required. Underflow is a situation when there is less number of keys in a node than the minimum number of keys it should hold. • Deletion Operation • Before going through the steps below, one must know these facts about a B+ tree of degree m(m=3). • A node can have a maximum of m children. (i.e. 3) • A node can contain a maximum of m - 1 keys. (i.e. 2) • A node should have a minimum of ⌈m/2⌉ children. (i.e. 2) • A node (except root node) should contain a minimum of ⌈m/2⌉ - 1 keys. (i.e. 1) • While deleting a key, we have to take care of the keys present in the internal nodes (i.e. indexes) as well because the values are redundant in a B+ tree. Search the key to be deleted then follow the following steps.
  • 30. Case I The key to be deleted is present only at the leaf node not in the indexes (or internal nodes). There are two cases for it: 1.There is more than the minimum number of keys in the node. Simply delete the key.
  • 31. 2) There is an exact minimum number of keys in the node. Delete the key and borrow a key from the immediate sibling. Add the median key of the sibling node to the parent.
  • 32. Case II The key to be deleted is present in the internal nodes as well. Then we have to remove them from the internal nodes as well. There are the following cases for this situation. 1) If there is more than the minimum number of keys in the node, simply delete the key from the leaf node and delete the key from the internal node as well. Fill the empty space in the internal node with the inorder successor.
  • 33. 2) If there is an exact minimum number of keys in the node, then delete the key and borrow a key from its immediate sibling (through the parent). Fill the empty space created in the index (internal node) with the borrowed key.
  • 34. 3) This case is similar to Case II(1) but here, empty space is generated above the immediate parent node. After deleting the key, merge the empty space with its sibling. Fill the empty space in the grandparent node with the inorder successor.
  • 35. Case III In this case, the height of the tree gets shrinked. It is a little complicated. Deleting 55 from the tree below leads to this condition. It can be understood in the illustrations below.
  • 36. B+ Tree Applications • Multilevel Indexing • Faster operations on the tree (insertion, deletion, search) • Database indexing