SlideShare uma empresa 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

Mais conteúdo relacionado

Mais procurados

Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureBalwant Gorad
 
THREADED BINARY TREE AND BINARY SEARCH TREE
THREADED BINARY TREE AND BINARY SEARCH TREETHREADED BINARY TREE AND BINARY SEARCH TREE
THREADED BINARY TREE AND BINARY SEARCH TREESiddhi Shrivas
 
Red black tree
Red black treeRed black tree
Red black treeRajendran
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queueSenthil Kumar
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data StructuresSHAKOOR AB
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationAmrinder Arora
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked ListNinad Mankar
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data StructureDharita Chokshi
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure shameen khan
 
Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm03446940736
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysissumitbardhan
 
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHIBCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHISowmya Jyothi
 
Propositional logic
Propositional logicPropositional logic
Propositional logicRushdi Shams
 

Mais procurados (20)

Searching
SearchingSearching
Searching
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
 
THREADED BINARY TREE AND BINARY SEARCH TREE
THREADED BINARY TREE AND BINARY SEARCH TREETHREADED BINARY TREE AND BINARY SEARCH TREE
THREADED BINARY TREE AND BINARY SEARCH TREE
 
Shadow paging
Shadow pagingShadow paging
Shadow paging
 
Red black tree
Red black treeRed black tree
Red black tree
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data Structures
 
Tree-In Data Structure
Tree-In Data StructureTree-In Data Structure
Tree-In Data Structure
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic Notation
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
Red black trees
Red black treesRed black trees
Red black trees
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
Data Structure and Algorithm - Divide and Conquer
Data Structure and Algorithm - Divide and ConquerData Structure and Algorithm - Divide and Conquer
Data Structure and Algorithm - Divide and Conquer
 
Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHIBCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 

Semelhante 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
 

Semelhante 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+ trees and height balance tree
B+ trees and height balance treeB+ trees and height balance tree
B+ trees and height balance tree
 
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
 

Último

Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...121011101441
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadaditya806802
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptMadan Karki
 
Steel Structures - Building technology.pptx
Steel Structures - Building technology.pptxSteel Structures - Building technology.pptx
Steel Structures - Building technology.pptxNikhil Raut
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm Systemirfanmechengr
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating SystemRashmi Bhat
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...Amil Baba Dawood bangali
 
System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingBootNeck1
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptJasonTagapanGulla
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionMebane Rash
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONTHE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONjhunlian
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncssuser2ae721
 
Vishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsVishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsSachinPawar510423
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 

Último (20)

Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasad
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.ppt
 
Steel Structures - Building technology.pptx
Steel Structures - Building technology.pptxSteel Structures - Building technology.pptx
Steel Structures - Building technology.pptx
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm System
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating System
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
 
System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event Scheduling
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.ppt
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of Action
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONTHE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
 
Vishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsVishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documents
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 

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