SlideShare une entreprise Scribd logo
1  sur  30
Data Structures
(B-Tree and B+ Tree )
Dr.N.S.Nithya
ASP/CSE
B-Tree
 B Tree & B+ Tree Data Structures are used to
Store Data in Disks When the Entire Data Cannot
be Stored in the Main Memory. Both are used for
multilevel indexing
Two main reason for implementing B-Tree
1. When the amount of data to be stored is very high,
we cannot store the entire data in the main memory.
Hence we store data in the disk. Data access from
the disk takes more time when compared to the
main memory access.
2.When the number of keys of the data stored in disks is
very high, the data is usually accessed in the form of
blocks. The time to access these blocks is directly
proportional to the height of the tree.
In AVL and Splay Tree has a binary structure of storing
only two values . B-trees are used to store more than
B-Tree
 B-Tree can be defined as a self-balanced
search tree with multiple keys in every node
and more than two children for every node.
 Here, number of keys in a node and number
of children for a node is depend on the
order of the B-Tree. Every B-Tree has order.
 AS more number of keys are placed in each
node of the B-Tree, the height of the B tree
is kept to a minimum.
 The main idea of using B-Trees is to reduce
the number of disk accesses.
 By keeping the height of the B-tree to the
minimum, the access is faster when
compared to other balanced trees like AVL
trees.
Representation of B-Tree
Ki are the search-key values (More than
one key value)
Pi are pointers to children (for non-leaf
nodes) or pointers to records (for leaf
nodes).
The search-keys in a node are ordered
(Ascending order)
K1 < K2 < K3 < . . . < Kn–1
Properties of the B-Tree
 All the leaf nodes must be at same level.
 All nodes except root must have at least
[m/2]-1 keys and maximum of m-1 keys.
 All non leaf nodes except root (i.e. all
internal nodes) must have at least m/2
children.
 The root node must have at least 2
children.
 A non leaf node with n-1 keys must have
n number of children.
 All the key values within a node must be
in Ascending Order.
B-Tree Examples
 For example, B-Tree of Order 4
(m)contains maximum 3(m-1) key
values in a node and maximum 4
(m)children for a node.
Basic Operations Of B-
Tree
Searching
Insertion (check
overflow)
Deletion (check
underflow)
Searching
 Searching in B tree is similar to that in
BST.
 In a Binary search tree, the search
process starts from the root node and
we make a 2-way decision every time
(we go to either left subtree or right
subtree).
 In B-Tree also search process starts
from the root node but here we make an
n-way decision every time. Where 'n' is
the total number of children the node
Searching the tree
keys < 7 keys > 16
7 < keys < 16
Insertion
 In a B-Tree, a new element must be added
only at the leaf node .
 When you are inserting a element in to a
leaf node ,check the node is full or not
 if number of keys=m-1 (m is order of tree)
,the node is full.
If the node is full then the following
operations are to be performed until the b-
tree property satisfies in all the level.
 Split
 Promote
Two basic operations
Example b –tree of order 3
 Split:
◦ When trying to add element to a full node
◦ Split node at middle value
 Promote:
◦ Sending the middle value to its parent.
◦ May require a new split
7
5
6
6
5 7
Insertions
 Construct a B-Tree of Order 3 by inserting
numbers from 1 to 7.
 Step 1:
 Step 2:
 Step 3:
◦ Split node in middle
1
1 2
1 2 3 2
1 3
Insertions
 Step 4:
 Step 5:
◦ Split
◦ Move up
5
3
2
1 4
3
2
1 4
4
2
1 3 5
Insertions
 Step 6:
 Step 7:
4
2
1 3 5 6
4
2
1 3 5 6 7
Step 7 continued
4
2
1 3 6
4 7
4
2
1 3
6
5 7
◦ Split
◦ Promote
Deletion
 For deletion we have to check underflow
Number of keys < m-1/2
 Case1: Leaf node with no underflow –
Delete the key
 Case2: Non-leaf node with underflow -
Delete the key and promote the
predecessor or successor key to the non-
leaf deleted key’s position.
 Case3:leaf node with few key sibling –
merge with the sibling
 Case4:leaf node with enough sibling-
Demote root key and promote leaf key
B-Trees 19
Type #1: Simple leaf deletion
12 29 52
2 7 9 15 22 56 69 72
31 43
Delete 2: Since there are enough
keys in the node, just delete it
Assuming a 4-way
B-Tree, as before...
Note when printed: this slide is animated
B-Trees 20
Type #2: Simple non-leaf
deletion
Delete 52 and promote 56(successor) to its
position
12 29 52
7 9 15 22 56 69 72
31 43
Delete 52
Borrow the predecessor
or (in this case) successor
56
Note when printed: this slide is animated
B-Trees 21
Type #3: Too few keys in node
and its siblings
12 29 56
7 9 15 22 69 72
31 43
Delete 72
Too few keys!
Join back together
Note when printed: this slide is animated
B-Trees 22
Type #3: Too few keys in node
and its siblings
12 29
7 9 15 22 69
56
31 43
Note when printed: this slide is animated
B-Trees 23
Type #4: Enough siblings
12 29
7 9 15 22 69
56
31 43
Delete 22
Demote root key and
promote leaf key
Note when printed: this slide is animated
B-Trees 24
Type #4: Enough siblings
12
29
7 9 15
31
69
56
43
Note when printed: this slide is animated
B+Tree
To implement dynamic multilevel indexing,
B-Tree and B+ tree are generally employed.
Drawback of B-tree
It stores the data pointer in each node at all
level. This will increase the number of level in
the tree thereby increase the searching time of
record.
B+ tree eliminates the above drawback by
storing data pointers only at the leaf nodes
of the tree.
The leaf nodes, therefore form the first
level of index, with the internal nodes
B -Tree and B+Tree
B+Tree
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+Trees are much easier and
higher performing to do a full
scan, as in look at every piece
of data that the tree indexes,
since the terminal nodes form
a linked list. To do a full scan
with a B-Tree you need to do a
full tree traversal to find all the
data.
Applications of B -Tree
A B-tree is a tree data structure
that keeps data sorted and
allows searches, insertions, and
deletions in logarithmic
amortized time.
Unlike self-balancing binary
search trees, it is optimized for
systems that read and write large
blocks of data. It is most
commonly used in database and
file systems.

Contenu connexe

Similaire à Data structures trees - B Tree & B+Tree.pptx

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
ssuser19bb13
 
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmmIndexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
RAtna29
 
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
 
btrees.ppt ttttttttttttttttttttttttttttt
btrees.ppt  tttttttttttttttttttttttttttttbtrees.ppt  ttttttttttttttttttttttttttttt
btrees.ppt ttttttttttttttttttttttttttttt
RAtna29
 

Similaire à Data structures trees - B Tree & B+Tree.pptx (20)

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
 
4-b-tree.ppt
4-b-tree.ppt4-b-tree.ppt
4-b-tree.ppt
 
Makalah if2091-2011-020
Makalah if2091-2011-020Makalah if2091-2011-020
Makalah if2091-2011-020
 
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmmIndexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
 
Indexing.ppt
Indexing.pptIndexing.ppt
Indexing.ppt
 
Presentation on b trees [autosaved]
Presentation on b trees [autosaved]Presentation on b trees [autosaved]
Presentation on b trees [autosaved]
 
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
 
B+ tree intro,uses,insertion and deletion
B+ tree intro,uses,insertion and deletionB+ tree intro,uses,insertion and deletion
B+ tree intro,uses,insertion and deletion
 
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 trees2
B trees2B trees2
B trees2
 
BTrees-fall2010.ppt
BTrees-fall2010.pptBTrees-fall2010.ppt
BTrees-fall2010.ppt
 
VCE Unit 05.pptx
VCE Unit 05.pptxVCE Unit 05.pptx
VCE Unit 05.pptx
 
B trees and_b__trees
B trees and_b__treesB trees and_b__trees
B trees and_b__trees
 
A41001011
A41001011A41001011
A41001011
 
Best for b trees
Best for b treesBest for b trees
Best for b trees
 
B tree by-jash acharya
B tree by-jash acharyaB tree by-jash acharya
B tree by-jash acharya
 
My File Structure Btrees Project Report
My File Structure Btrees Project ReportMy File Structure Btrees Project Report
My File Structure Btrees Project Report
 
btrees.ppt ttttttttttttttttttttttttttttt
btrees.ppt  tttttttttttttttttttttttttttttbtrees.ppt  ttttttttttttttttttttttttttttt
btrees.ppt ttttttttttttttttttttttttttttt
 
B trees dbms
B trees dbmsB trees dbms
B trees dbms
 
Unit-5 Advanced tree zxcppt
Unit-5 Advanced tree                     zxcpptUnit-5 Advanced tree                     zxcppt
Unit-5 Advanced tree zxcppt
 

Plus de MalligaarjunanN

Plus de MalligaarjunanN (20)

bro_nodejs-1 front end development .pdf
bro_nodejs-1 front end development  .pdfbro_nodejs-1 front end development  .pdf
bro_nodejs-1 front end development .pdf
 
Microprocessor and microcontroller record.pdf
Microprocessor and microcontroller record.pdfMicroprocessor and microcontroller record.pdf
Microprocessor and microcontroller record.pdf
 
8087 MICROPROCESSOR and diagram with definition.pdf
8087 MICROPROCESSOR and diagram with definition.pdf8087 MICROPROCESSOR and diagram with definition.pdf
8087 MICROPROCESSOR and diagram with definition.pdf
 
8089 microprocessor with diagram and analytical
8089 microprocessor with diagram and analytical8089 microprocessor with diagram and analytical
8089 microprocessor with diagram and analytical
 
English article power point presentation eng.pptx
English article power point presentation eng.pptxEnglish article power point presentation eng.pptx
English article power point presentation eng.pptx
 
Digital principle and computer design Presentation (1).pptx
Digital principle and computer design Presentation (1).pptxDigital principle and computer design Presentation (1).pptx
Digital principle and computer design Presentation (1).pptx
 
Technical English grammar and tenses.pptx
Technical English grammar and tenses.pptxTechnical English grammar and tenses.pptx
Technical English grammar and tenses.pptx
 
Polymorphism topic power point presentation li.pptx
Polymorphism topic power point presentation li.pptxPolymorphism topic power point presentation li.pptx
Polymorphism topic power point presentation li.pptx
 
Chemistry iconic bond topic chem ppt.pptx
Chemistry iconic bond topic chem ppt.pptxChemistry iconic bond topic chem ppt.pptx
Chemistry iconic bond topic chem ppt.pptx
 
C programming DOC-20230723-WA0001..pptx
C programming  DOC-20230723-WA0001..pptxC programming  DOC-20230723-WA0001..pptx
C programming DOC-20230723-WA0001..pptx
 
Chemistry fluorescent topic chemistry.pptx
Chemistry fluorescent topic  chemistry.pptxChemistry fluorescent topic  chemistry.pptx
Chemistry fluorescent topic chemistry.pptx
 
C programming power point presentation c ppt.pptx
C programming power point presentation c ppt.pptxC programming power point presentation c ppt.pptx
C programming power point presentation c ppt.pptx
 
Inheritance_Polymorphism_Overloading_overriding.pptx
Inheritance_Polymorphism_Overloading_overriding.pptxInheritance_Polymorphism_Overloading_overriding.pptx
Inheritance_Polymorphism_Overloading_overriding.pptx
 
Python programming file handling mhhk.pptx
Python programming file handling mhhk.pptxPython programming file handling mhhk.pptx
Python programming file handling mhhk.pptx
 
Computer organisation and architecture updated unit 2 COA ppt.pptx
Computer organisation and architecture updated unit 2 COA ppt.pptxComputer organisation and architecture updated unit 2 COA ppt.pptx
Computer organisation and architecture updated unit 2 COA ppt.pptx
 
Data structures trees and graphs - Heap Tree.pptx
Data structures trees and graphs - Heap Tree.pptxData structures trees and graphs - Heap Tree.pptx
Data structures trees and graphs - Heap Tree.pptx
 
Data structures trees and graphs - AVL tree.pptx
Data structures trees and graphs - AVL  tree.pptxData structures trees and graphs - AVL  tree.pptx
Data structures trees and graphs - AVL tree.pptx
 
Computer organisation and architecture .
Computer organisation and architecture .Computer organisation and architecture .
Computer organisation and architecture .
 
Python programming variables and comment
Python programming variables and commentPython programming variables and comment
Python programming variables and comment
 
pythoncommentsandvariables-231016105804-9a780b91 (1).pptx
pythoncommentsandvariables-231016105804-9a780b91 (1).pptxpythoncommentsandvariables-231016105804-9a780b91 (1).pptx
pythoncommentsandvariables-231016105804-9a780b91 (1).pptx
 

Dernier

一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理
一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理
一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理
pyhepag
 
一比一原版阿德莱德大学毕业证成绩单如何办理
一比一原版阿德莱德大学毕业证成绩单如何办理一比一原版阿德莱德大学毕业证成绩单如何办理
一比一原版阿德莱德大学毕业证成绩单如何办理
pyhepag
 
Fuzzy Sets decision making under information of uncertainty
Fuzzy Sets decision making under information of uncertaintyFuzzy Sets decision making under information of uncertainty
Fuzzy Sets decision making under information of uncertainty
RafigAliyev2
 
一比一原版麦考瑞大学毕业证成绩单如何办理
一比一原版麦考瑞大学毕业证成绩单如何办理一比一原版麦考瑞大学毕业证成绩单如何办理
一比一原版麦考瑞大学毕业证成绩单如何办理
cyebo
 
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
pyhepag
 
Abortion pills in Dammam Saudi Arabia// +966572737505 // buy cytotec
Abortion pills in Dammam Saudi Arabia// +966572737505 // buy cytotecAbortion pills in Dammam Saudi Arabia// +966572737505 // buy cytotec
Abortion pills in Dammam Saudi Arabia// +966572737505 // buy cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
一比一原版西悉尼大学毕业证成绩单如何办理
一比一原版西悉尼大学毕业证成绩单如何办理一比一原版西悉尼大学毕业证成绩单如何办理
一比一原版西悉尼大学毕业证成绩单如何办理
pyhepag
 

Dernier (20)

一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理
一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理
一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理
 
Artificial_General_Intelligence__storm_gen_article.pdf
Artificial_General_Intelligence__storm_gen_article.pdfArtificial_General_Intelligence__storm_gen_article.pdf
Artificial_General_Intelligence__storm_gen_article.pdf
 
Supply chain analytics to combat the effects of Ukraine-Russia-conflict
Supply chain analytics to combat the effects of Ukraine-Russia-conflictSupply chain analytics to combat the effects of Ukraine-Russia-conflict
Supply chain analytics to combat the effects of Ukraine-Russia-conflict
 
一比一原版阿德莱德大学毕业证成绩单如何办理
一比一原版阿德莱德大学毕业证成绩单如何办理一比一原版阿德莱德大学毕业证成绩单如何办理
一比一原版阿德莱德大学毕业证成绩单如何办理
 
2024 Q1 Tableau User Group Leader Quarterly Call
2024 Q1 Tableau User Group Leader Quarterly Call2024 Q1 Tableau User Group Leader Quarterly Call
2024 Q1 Tableau User Group Leader Quarterly Call
 
Fuzzy Sets decision making under information of uncertainty
Fuzzy Sets decision making under information of uncertaintyFuzzy Sets decision making under information of uncertainty
Fuzzy Sets decision making under information of uncertainty
 
2024 Q2 Orange County (CA) Tableau User Group Meeting
2024 Q2 Orange County (CA) Tableau User Group Meeting2024 Q2 Orange County (CA) Tableau User Group Meeting
2024 Q2 Orange County (CA) Tableau User Group Meeting
 
Data analytics courses in Nepal Presentation
Data analytics courses in Nepal PresentationData analytics courses in Nepal Presentation
Data analytics courses in Nepal Presentation
 
How I opened a fake bank account and didn't go to prison
How I opened a fake bank account and didn't go to prisonHow I opened a fake bank account and didn't go to prison
How I opened a fake bank account and didn't go to prison
 
basics of data science with application areas.pdf
basics of data science with application areas.pdfbasics of data science with application areas.pdf
basics of data science with application areas.pdf
 
一比一原版麦考瑞大学毕业证成绩单如何办理
一比一原版麦考瑞大学毕业证成绩单如何办理一比一原版麦考瑞大学毕业证成绩单如何办理
一比一原版麦考瑞大学毕业证成绩单如何办理
 
Machine Learning for Accident Severity Prediction
Machine Learning for Accident Severity PredictionMachine Learning for Accident Severity Prediction
Machine Learning for Accident Severity Prediction
 
Easy and simple project file on mp online
Easy and simple project file on mp onlineEasy and simple project file on mp online
Easy and simple project file on mp online
 
Pre-ProductionImproveddsfjgndflghtgg.pptx
Pre-ProductionImproveddsfjgndflghtgg.pptxPre-ProductionImproveddsfjgndflghtgg.pptx
Pre-ProductionImproveddsfjgndflghtgg.pptx
 
Webinar One View, Multiple Systems No-Code Integration of Salesforce and ERPs
Webinar One View, Multiple Systems No-Code Integration of Salesforce and ERPsWebinar One View, Multiple Systems No-Code Integration of Salesforce and ERPs
Webinar One View, Multiple Systems No-Code Integration of Salesforce and ERPs
 
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
 
AI Imagen for data-storytelling Infographics.pdf
AI Imagen for data-storytelling Infographics.pdfAI Imagen for data-storytelling Infographics.pdf
AI Imagen for data-storytelling Infographics.pdf
 
Atlantic Grupa Case Study (Mintec Data AI)
Atlantic Grupa Case Study (Mintec Data AI)Atlantic Grupa Case Study (Mintec Data AI)
Atlantic Grupa Case Study (Mintec Data AI)
 
Abortion pills in Dammam Saudi Arabia// +966572737505 // buy cytotec
Abortion pills in Dammam Saudi Arabia// +966572737505 // buy cytotecAbortion pills in Dammam Saudi Arabia// +966572737505 // buy cytotec
Abortion pills in Dammam Saudi Arabia// +966572737505 // buy cytotec
 
一比一原版西悉尼大学毕业证成绩单如何办理
一比一原版西悉尼大学毕业证成绩单如何办理一比一原版西悉尼大学毕业证成绩单如何办理
一比一原版西悉尼大学毕业证成绩单如何办理
 

Data structures trees - B Tree & B+Tree.pptx

  • 1. Data Structures (B-Tree and B+ Tree ) Dr.N.S.Nithya ASP/CSE
  • 2. B-Tree  B Tree & B+ Tree Data Structures are used to Store Data in Disks When the Entire Data Cannot be Stored in the Main Memory. Both are used for multilevel indexing Two main reason for implementing B-Tree 1. When the amount of data to be stored is very high, we cannot store the entire data in the main memory. Hence we store data in the disk. Data access from the disk takes more time when compared to the main memory access. 2.When the number of keys of the data stored in disks is very high, the data is usually accessed in the form of blocks. The time to access these blocks is directly proportional to the height of the tree. In AVL and Splay Tree has a binary structure of storing only two values . B-trees are used to store more than
  • 3. B-Tree  B-Tree can be defined as a self-balanced search tree with multiple keys in every node and more than two children for every node.  Here, number of keys in a node and number of children for a node is depend on the order of the B-Tree. Every B-Tree has order.  AS more number of keys are placed in each node of the B-Tree, the height of the B tree is kept to a minimum.  The main idea of using B-Trees is to reduce the number of disk accesses.  By keeping the height of the B-tree to the minimum, the access is faster when compared to other balanced trees like AVL trees.
  • 4. Representation of B-Tree Ki are the search-key values (More than one key value) Pi are pointers to children (for non-leaf nodes) or pointers to records (for leaf nodes). The search-keys in a node are ordered (Ascending order) K1 < K2 < K3 < . . . < Kn–1
  • 5. Properties of the B-Tree  All the leaf nodes must be at same level.  All nodes except root must have at least [m/2]-1 keys and maximum of m-1 keys.  All non leaf nodes except root (i.e. all internal nodes) must have at least m/2 children.  The root node must have at least 2 children.  A non leaf node with n-1 keys must have n number of children.  All the key values within a node must be in Ascending Order.
  • 6. B-Tree Examples  For example, B-Tree of Order 4 (m)contains maximum 3(m-1) key values in a node and maximum 4 (m)children for a node.
  • 7. Basic Operations Of B- Tree Searching Insertion (check overflow) Deletion (check underflow)
  • 8. Searching  Searching in B tree is similar to that in BST.  In a Binary search tree, the search process starts from the root node and we make a 2-way decision every time (we go to either left subtree or right subtree).  In B-Tree also search process starts from the root node but here we make an n-way decision every time. Where 'n' is the total number of children the node
  • 9. Searching the tree keys < 7 keys > 16 7 < keys < 16
  • 10. Insertion  In a B-Tree, a new element must be added only at the leaf node .  When you are inserting a element in to a leaf node ,check the node is full or not  if number of keys=m-1 (m is order of tree) ,the node is full. If the node is full then the following operations are to be performed until the b- tree property satisfies in all the level.  Split  Promote
  • 11. Two basic operations Example b –tree of order 3  Split: ◦ When trying to add element to a full node ◦ Split node at middle value  Promote: ◦ Sending the middle value to its parent. ◦ May require a new split 7 5 6 6 5 7
  • 12. Insertions  Construct a B-Tree of Order 3 by inserting numbers from 1 to 7.  Step 1:  Step 2:  Step 3: ◦ Split node in middle 1 1 2 1 2 3 2 1 3
  • 13. Insertions  Step 4:  Step 5: ◦ Split ◦ Move up 5 3 2 1 4 3 2 1 4 4 2 1 3 5
  • 14. Insertions  Step 6:  Step 7: 4 2 1 3 5 6 4 2 1 3 5 6 7
  • 15. Step 7 continued 4 2 1 3 6 4 7 4 2 1 3 6 5 7 ◦ Split ◦ Promote
  • 16.
  • 17.
  • 18. Deletion  For deletion we have to check underflow Number of keys < m-1/2  Case1: Leaf node with no underflow – Delete the key  Case2: Non-leaf node with underflow - Delete the key and promote the predecessor or successor key to the non- leaf deleted key’s position.  Case3:leaf node with few key sibling – merge with the sibling  Case4:leaf node with enough sibling- Demote root key and promote leaf key
  • 19. B-Trees 19 Type #1: Simple leaf deletion 12 29 52 2 7 9 15 22 56 69 72 31 43 Delete 2: Since there are enough keys in the node, just delete it Assuming a 4-way B-Tree, as before... Note when printed: this slide is animated
  • 20. B-Trees 20 Type #2: Simple non-leaf deletion Delete 52 and promote 56(successor) to its position 12 29 52 7 9 15 22 56 69 72 31 43 Delete 52 Borrow the predecessor or (in this case) successor 56 Note when printed: this slide is animated
  • 21. B-Trees 21 Type #3: Too few keys in node and its siblings 12 29 56 7 9 15 22 69 72 31 43 Delete 72 Too few keys! Join back together Note when printed: this slide is animated
  • 22. B-Trees 22 Type #3: Too few keys in node and its siblings 12 29 7 9 15 22 69 56 31 43 Note when printed: this slide is animated
  • 23. B-Trees 23 Type #4: Enough siblings 12 29 7 9 15 22 69 56 31 43 Delete 22 Demote root key and promote leaf key Note when printed: this slide is animated
  • 24. B-Trees 24 Type #4: Enough siblings 12 29 7 9 15 31 69 56 43 Note when printed: this slide is animated
  • 25. B+Tree To implement dynamic multilevel indexing, B-Tree and B+ tree are generally employed. Drawback of B-tree It stores the data pointer in each node at all level. This will increase the number of level in the tree thereby increase the searching time of record. B+ tree eliminates the above drawback by storing data pointers only at the leaf nodes of the tree. The leaf nodes, therefore form the first level of index, with the internal nodes
  • 26.
  • 27. B -Tree and B+Tree B+Tree
  • 28. 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..
  • 29. B+Trees are much easier and higher performing to do a full scan, as in look at every piece of data that the tree indexes, since the terminal nodes form a linked list. To do a full scan with a B-Tree you need to do a full tree traversal to find all the data.
  • 30. Applications of B -Tree A B-tree is a tree data structure that keeps data sorted and allows searches, insertions, and deletions in logarithmic amortized time. Unlike self-balancing binary search trees, it is optimized for systems that read and write large blocks of data. It is most commonly used in database and file systems.