SlideShare a Scribd company logo
Indexing
B+ Tree
B+ Tree Properties
● Every Tree has an order of “n”
● All nodes on the left have smaller values than a key and all nodes on the right
have greater than or equal values than a key.
Each node has the
following properties
Max Min
Children root/internal: n
Leaf: 0
Root: 2 (if root is not leaf as well)
Internal: n/2
⌈ ⌉
Keys/Values n-1 Root: 1
Leaf and Internal: n/2 -1
⌈ ⌉
[Note: for simplicity leaf and internal is
considered same in some resources,
otherwise leaf min is (n-1)/2 ]
⌈ ⌉
B+ Tree (Insertion)
Insertion Algorithm:
1. Find the right spot (leaf node): Start from the top (root) and move down the
tree, following the correct path (based on the key you want to insert), until you
reach a leaf node.
2. Insert if node has less than “max” keys: If that leaf node has space (less
than the max number of keys allowed), just insert the value in sorted order.
B+ Tree (Insertion)
3. Split if node has “max” keys: If the leaf is already full, split it into half. Put
first half on a new left leaf and the second half on a new right leaf. Send up the
lowest key from the new right node to the parent
4. Repeat the split upwards if needed: If the parent now becomes full too, split
it as well and push a key further up. If a non-leaf node is split, the lowest value
on the right will only be moved up and not copied to the new right leaf. This
might continue up to the root. If the root splits, a new root will be created and the
tree height will increase.
B+ Tree (Insertion)
Difference between splitting a leaf node vs a
non-leaf(root/internal) node [for n= 4]
Leaf Node
Non-Leaf Node
B+ Tree (Insertion)
Insert the following in a B+ tree of order 4 according to the given sequence:
4, 10, 7, 12, 1, 5, 2, 25, 15, 9, 18, 20
**Use the following B+ tree simulator (
https://www.cs.usfca.edu/~galles/visualization/BPlusTree.html)
Here, max keys in a node = 4 - 1 = 3
1. Inserting 4, 10, 7 2. Inserting 12 3. Inserting 1
B+ Tree (Insertion)
4. Inserting 5 5. Inserting 2, 25 6.Inserting 15
7. Inserting 9, 18 8. Inserting 20
B+ Tree (Insertion)
● If the keys have String values, then sorting should be done according to the “dictionary”
order.
● If order of B+ tree is odd (e.g. n=3), then create a right-biased or left-biased tree.
Maintain the same bias for the entire tree.
INSERTING 4, 10 , 7
B+ Tree (Deletion)
CASE 1 (No. of Keys > “Min” Keys allowed)
CASE 2 (No. of Keys = “Min” Keys allowed, Sibling Nodes have > “Min” Keys
allowed)
CASE 3 (No. of Keys = “Min” Keys allowed, Sibling Nodes also do not have “Min”
Keys allowed)
CASE 4 (Internal Nodes: No. of Keys = “Min” Keys allowed)
CASE 5 (Shrinking of Tree)
B+ Tree (Deletion)
CASE 1 (No. of Keys > “Min” Keys allowed)
For n = 4, leaf/internal node min = n/2 -1 = 4/2 -1 = 1
⌈ ⌉ ⌈ ⌉
Example 1: Delete 7 -> Find 7 (in leaf node and internal nodes) and remove
B+ Tree (Deletion)
CASE 1 (No. of Keys > “Min” Keys allowed)
Example 2: Delete 15 -> Find 15 (in leaf node and internal nodes) and remove. If removed
from internal nodes, then replace with the lowest key from right subtree.
B+ Tree (Deletion)
CASE 2 (No. of Keys = “Min” Keys allowed, Sibling Nodes have > “Min”
Keys allowed)
Example 1: Delete 12 -> Find key, borrow from left/right sibling through the parent.
For internal nodes/parents, copy lowest key from right subtree.
B+ Tree (Deletion)
CASE 2 (No. of Keys = “Min” Keys allowed, Sibling Nodes have > “Min”
Keys allowed)
Example 2: Delete 18 -> Find key, borrow from left/right sibling through the parent.
For internal nodes/parents, copy lowest key from right subtree.
B+ Tree (Deletion)
CASE 3 (No. of Keys = “Min” Keys allowed, Sibling Nodes also have only
“Min” Keys allowed, Parent has greater than min allowed)
Example 1: Delete 9 -> Find key, Merge with sibling, remove parent key (if Parent
Node no.of keys> “Min” keys allowed)
B+ Tree (Deletion)
CASE 4 (Internal Nodes: No. of Keys = “Min” Keys allowed)
Example 1: Delete 25-> Find 20 in leaf and use case 3 since case 2 not possible. Now
Parent has less than “min” no. of keys. Parent borrows from/merges with sibling and
adjust children according to B+ properties. If internal nodes merge, they merge with sibling
node and parent key.
B+ Tree (Deletion)
CASE 5 (Shrinking of Tree: Same conditions as case 4)
Example 1: Delete 20-> Find 20, use case 3 for leaf. For internal nodes, merge with sibling
and parent, tree height will shrink if parent node has 1 key. Adjust children according to B+
tree properties.
Summary
Summary

More Related Content

Similar to Indexing & Hashing - Indexing using B+ Tree (20)

PPT
btrees.ppt ttttttttttttttttttttttttttttt
RAtna29
 
PPT
b+ tree
bitistu
 
PDF
B TREE ( a to z concept ) in data structure or DBMS
MathkeBhoot
 
PDF
Jamal ppt b+tree dbms
JamalMohammedS
 
PPTX
Data structures trees - B Tree & B+Tree.pptx
MalligaarjunanN
 
PPTX
B tree
Tech_MX
 
PPT
16807097.ppt b tree are a good data structure
SadiaSharmin40
 
PPTX
Nikhat b+ trees ppt
Nikihat Maniyar
 
PPTX
B tree
Fatimah Alqadheeb
 
PPTX
B+tree Data structures presentation
Muhammad Bilal Khan
 
PPT
B trees and_b__trees
meghu123
 
PPT
B-and-B-Tree-ppt presentation in data structure
ssuser19bb13
 
PPTX
BPlus_Tree_Presentation_for_DBMS_Indexing.pptx
fakeid17861
 
PPTX
Presentation on b trees [autosaved]
AKASHKUMAR1542
 
PDF
A41001011
ijceronline
 
PPTX
presentation for seminar with easiest way
r7574949
 
PPT
109885098-B-Trees-And-B-Trees in data structure.ppt
ssuser19bb13
 
PPT
B trees and_b__trees
Rakhi Srivastava
 
PPTX
B best on presentation on tree ppt.pptx
PRABHATMISHRA969924
 
btrees.ppt ttttttttttttttttttttttttttttt
RAtna29
 
b+ tree
bitistu
 
B TREE ( a to z concept ) in data structure or DBMS
MathkeBhoot
 
Jamal ppt b+tree dbms
JamalMohammedS
 
Data structures trees - B Tree & B+Tree.pptx
MalligaarjunanN
 
B tree
Tech_MX
 
16807097.ppt b tree are a good data structure
SadiaSharmin40
 
Nikhat b+ trees ppt
Nikihat Maniyar
 
B+tree Data structures presentation
Muhammad Bilal Khan
 
B trees and_b__trees
meghu123
 
B-and-B-Tree-ppt presentation in data structure
ssuser19bb13
 
BPlus_Tree_Presentation_for_DBMS_Indexing.pptx
fakeid17861
 
Presentation on b trees [autosaved]
AKASHKUMAR1542
 
A41001011
ijceronline
 
presentation for seminar with easiest way
r7574949
 
109885098-B-Trees-And-B-Trees in data structure.ppt
ssuser19bb13
 
B trees and_b__trees
Rakhi Srivastava
 
B best on presentation on tree ppt.pptx
PRABHATMISHRA969924
 

Recently uploaded (20)

PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
People & Earth's Ecosystem -Lesson 2: People & Population
marvinnbustamante1
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
People & Earth's Ecosystem -Lesson 2: People & Population
marvinnbustamante1
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
Ad

Indexing & Hashing - Indexing using B+ Tree

  • 2. B+ Tree Properties ● Every Tree has an order of “n” ● All nodes on the left have smaller values than a key and all nodes on the right have greater than or equal values than a key. Each node has the following properties Max Min Children root/internal: n Leaf: 0 Root: 2 (if root is not leaf as well) Internal: n/2 ⌈ ⌉ Keys/Values n-1 Root: 1 Leaf and Internal: n/2 -1 ⌈ ⌉ [Note: for simplicity leaf and internal is considered same in some resources, otherwise leaf min is (n-1)/2 ] ⌈ ⌉
  • 3. B+ Tree (Insertion) Insertion Algorithm: 1. Find the right spot (leaf node): Start from the top (root) and move down the tree, following the correct path (based on the key you want to insert), until you reach a leaf node. 2. Insert if node has less than “max” keys: If that leaf node has space (less than the max number of keys allowed), just insert the value in sorted order.
  • 4. B+ Tree (Insertion) 3. Split if node has “max” keys: If the leaf is already full, split it into half. Put first half on a new left leaf and the second half on a new right leaf. Send up the lowest key from the new right node to the parent 4. Repeat the split upwards if needed: If the parent now becomes full too, split it as well and push a key further up. If a non-leaf node is split, the lowest value on the right will only be moved up and not copied to the new right leaf. This might continue up to the root. If the root splits, a new root will be created and the tree height will increase.
  • 5. B+ Tree (Insertion) Difference between splitting a leaf node vs a non-leaf(root/internal) node [for n= 4] Leaf Node Non-Leaf Node
  • 6. B+ Tree (Insertion) Insert the following in a B+ tree of order 4 according to the given sequence: 4, 10, 7, 12, 1, 5, 2, 25, 15, 9, 18, 20 **Use the following B+ tree simulator ( https://www.cs.usfca.edu/~galles/visualization/BPlusTree.html) Here, max keys in a node = 4 - 1 = 3 1. Inserting 4, 10, 7 2. Inserting 12 3. Inserting 1
  • 7. B+ Tree (Insertion) 4. Inserting 5 5. Inserting 2, 25 6.Inserting 15 7. Inserting 9, 18 8. Inserting 20
  • 8. B+ Tree (Insertion) ● If the keys have String values, then sorting should be done according to the “dictionary” order. ● If order of B+ tree is odd (e.g. n=3), then create a right-biased or left-biased tree. Maintain the same bias for the entire tree. INSERTING 4, 10 , 7
  • 9. B+ Tree (Deletion) CASE 1 (No. of Keys > “Min” Keys allowed) CASE 2 (No. of Keys = “Min” Keys allowed, Sibling Nodes have > “Min” Keys allowed) CASE 3 (No. of Keys = “Min” Keys allowed, Sibling Nodes also do not have “Min” Keys allowed) CASE 4 (Internal Nodes: No. of Keys = “Min” Keys allowed) CASE 5 (Shrinking of Tree)
  • 10. B+ Tree (Deletion) CASE 1 (No. of Keys > “Min” Keys allowed) For n = 4, leaf/internal node min = n/2 -1 = 4/2 -1 = 1 ⌈ ⌉ ⌈ ⌉ Example 1: Delete 7 -> Find 7 (in leaf node and internal nodes) and remove
  • 11. B+ Tree (Deletion) CASE 1 (No. of Keys > “Min” Keys allowed) Example 2: Delete 15 -> Find 15 (in leaf node and internal nodes) and remove. If removed from internal nodes, then replace with the lowest key from right subtree.
  • 12. B+ Tree (Deletion) CASE 2 (No. of Keys = “Min” Keys allowed, Sibling Nodes have > “Min” Keys allowed) Example 1: Delete 12 -> Find key, borrow from left/right sibling through the parent. For internal nodes/parents, copy lowest key from right subtree.
  • 13. B+ Tree (Deletion) CASE 2 (No. of Keys = “Min” Keys allowed, Sibling Nodes have > “Min” Keys allowed) Example 2: Delete 18 -> Find key, borrow from left/right sibling through the parent. For internal nodes/parents, copy lowest key from right subtree.
  • 14. B+ Tree (Deletion) CASE 3 (No. of Keys = “Min” Keys allowed, Sibling Nodes also have only “Min” Keys allowed, Parent has greater than min allowed) Example 1: Delete 9 -> Find key, Merge with sibling, remove parent key (if Parent Node no.of keys> “Min” keys allowed)
  • 15. B+ Tree (Deletion) CASE 4 (Internal Nodes: No. of Keys = “Min” Keys allowed) Example 1: Delete 25-> Find 20 in leaf and use case 3 since case 2 not possible. Now Parent has less than “min” no. of keys. Parent borrows from/merges with sibling and adjust children according to B+ properties. If internal nodes merge, they merge with sibling node and parent key.
  • 16. B+ Tree (Deletion) CASE 5 (Shrinking of Tree: Same conditions as case 4) Example 1: Delete 20-> Find 20, use case 3 for leaf. For internal nodes, merge with sibling and parent, tree height will shrink if parent node has 1 key. Adjust children according to B+ tree properties.