SlideShare a Scribd company logo
Chapter 15 B
External Methods –
B-Trees
© 2004 Pearson Addison-Wesley. All rights reserved 15 B-2
B-Trees
• To organize the index file as an external search tree
– Use block numbers for child pointers
• A child pointer value of –1 is used as the null pointer
Figure 15.10a –Figure 15.10a – Blocks organized into a 2-3 tree
© 2004 Pearson Addison-Wesley. All rights reserved 15 B-3
B-Trees
• If the index file is organized into a 2-3 tree
– Each node would contain
• Either one or two index records, each of the form
<key, pointer>
• Three child pointers
Figure 15.10b –Figure 15.10b – A single node of the 2-3 tree
© 2004 Pearson Addison-Wesley. All rights reserved 15 B-4
B-Trees
• An external 2-3 tree is adequate, but an
improvement is possible
• To improve efficiency
– Allow each node to have as many children as possible
• In an external environment, the advantage of keeping a search
tree short far outweighs the disadvantage of performing extra
work at each node
• Block size should be the only limiting factor for the number of
children
© 2004 Pearson Addison-Wesley. All rights reserved 15 B-5
B-Trees
• Binary search tree
– If a node N has two children, it must contain one key
value
• 2-3 tree
– If a node N has three children, it must contain two key
values
• General search tree
– If a node N has m children, it must contain m – 1 key
values
© 2004 Pearson Addison-Wesley. All rights reserved 15 B-6
B-Trees
Figure 15.11Figure 15.11
a) A node with two children; b) a node with three children; c) a node with m children
© 2004 Pearson Addison-Wesley. All rights reserved 15 B-7
B-Trees
• B-tree of degree m
– All leaves are at the same level
– Nodes
• Each node contains between m – 1 and m/2 records
• Each internal node has one more child than it has records
• Exception: The root can contain as few as one record and can
have as few as two children
– Example
• A 2-3 tree is a B-tree of degree 3
– Each node contains between (3-1) = 2 and 3/2 = 1 records.
© 2004 Pearson Addison-Wesley. All rights reserved 15 B-8
B-Trees
Figure 15.13Figure 15.13
A B-tree of degree 5
© 2004 Pearson Addison-Wesley. All rights reserved 15 B-9
B-Trees
• Retrieval
– Generalized search tree retrieval
• Insertion into a B-tree
– Step 1: Insert the data record into the data file
– Step 2: Insert a corresponding index record into
the index file
© 2004 Pearson Addison-Wesley. All rights reserved 15 B-10
B-Trees
Figure 15.14a and bFigure 15.14a and b
The steps for inserting 55
© 2004 Pearson Addison-Wesley. All rights reserved 15 B-11
B-Trees
Figure 15.14c-eFigure 15.14c-e
The steps for inserting 55
© 2004 Pearson Addison-Wesley. All rights reserved 15 B-12
B-Trees
• Deletion from a B-tree
– Step 1: Locate the index record in the index file
and delete it from the index file
– Step 2: Delete the data record from the data file
© 2004 Pearson Addison-Wesley. All rights reserved 15 B-13
B-Trees
Figure 15.15a and bFigure 15.15a and b
The steps for deleting 73
© 2004 Pearson Addison-Wesley. All rights reserved 15 B-14
B-Trees
Figure 15.15cFigure 15.15c
The steps for deleting 73
© 2004 Pearson Addison-Wesley. All rights reserved 15 B-15
B-Trees
Figure 15.15dFigure 15.15d
The steps for deleting 73
© 2004 Pearson Addison-Wesley. All rights reserved 15 B-16
B-Trees
Figure 14.15e and fFigure 14.15e and f
The steps for deleting 73
© 2004 Pearson Addison-Wesley. All rights reserved 15 B-17
Traversals
• Accessing only the search key of each record, not
the data file
– Not efficiently supported by the hashing
implementation
– Efficiently supported by the B-tree implementation
• The search keys can be visited in sorted order by using an
inorder traversal of the B-tree
• Accessing the entire data record
– Not efficiently supported by the B-tree implementation
© 2004 Pearson Addison-Wesley. All rights reserved 15 B-18
Multiple Indexing
• Advantage
– Allows multiple data organizations
• Disadvantage
– More storage space
– Additional overhead for updating each index
whenever the data file is modified
© 2004 Pearson Addison-Wesley. All rights reserved 15 B-19
Multiple Indexing
Figure 15.16Figure 15.16
Multiple index files
Chi-Cheng Lin, Winona State University 20
Variations of B-Trees
• The fewer nodes are in a B-tree, the better.
(Why?)
• Problems of B-tree:
– It could be only half full
• More nodes required
• Space wasted
– Inorder traversal “jumps” around nodes
• B*
-Trees: introduced by Donald Knuth
• B+
-Trees: introduced by H. Wedekind
Chi-Cheng Lin, Winona State University 21
B*
-Trees
• B*
-tree of degree m
– All leaves are at the same level
– Nodes
• Each node contains between m – 1 and (2m – 1)/3 records
• Each internal node has one more child than it has records
• Exception: The root can contain as few as one record and as
many as (2m-2) children
– Example
• B*
-tree of degree 9
– Each node contains between (9 – 1) = 8 and (2×9 – 1)/3 = 5
records.
Chi-Cheng Lin, Winona State University 22
B*
-Trees
• Splitting nodes
– When a node overflows, it is not split right away
– A split is delayed by redistributing the keys between a
node and its sibling
– When both a node and its sibling are full, an insertion
to the node will split the two nodes into three nodes
• A B*-Tree is always two-third full instead of half
full  number of nodes in the tree is reduced
Chi-Cheng Lin, Winona State University 23
B*
-Trees
Chi-Cheng Lin, Winona State University 24
B+
-Trees
• References to data are only made from the
leaves
– All index records can be found from the leaves
• Two sets of nodes
– Index set
• Internal nodes
• Provides fast access of data
– Sequence set
• Leaves, linked sequentially
• Provides efficient inorder traversal
Chi-Cheng Lin, Winona State University 25
B+
-Trees

More Related Content

Viewers also liked

B trees
B treesB trees
Algorithm Introduction #18 B-Tree
Algorithm Introduction #18 B-TreeAlgorithm Introduction #18 B-Tree
Algorithm Introduction #18 B-Tree
Satoshi Asano
 
Лекция 5: B-деревья (B-trees, k-way merge sort)
Лекция 5: B-деревья (B-trees, k-way merge sort)Лекция 5: B-деревья (B-trees, k-way merge sort)
Лекция 5: B-деревья (B-trees, k-way merge sort)Mikhail Kurnosov
 
B trees and_b__trees
B trees and_b__treesB trees and_b__trees
B trees and_b__trees
meghu123
 
CAD: introduction to floorplanning
CAD:  introduction to floorplanningCAD:  introduction to floorplanning
CAD: introduction to floorplanning
Team-VLSI-ITMU
 
floor planning
floor planningfloor planning
floor planning
Team-VLSI-ITMU
 
Best for b trees
Best for b treesBest for b trees
Best for b trees
DineshRaaja
 
Examining Mac File Structures
Examining Mac File StructuresExamining Mac File Structures
Examining Mac File Structures
primeteacher32
 
17. Trees and Graphs
17. Trees and Graphs17. Trees and Graphs
17. Trees and Graphs
Intro C# Book
 

Viewers also liked (9)

B trees
B treesB trees
B trees
 
Algorithm Introduction #18 B-Tree
Algorithm Introduction #18 B-TreeAlgorithm Introduction #18 B-Tree
Algorithm Introduction #18 B-Tree
 
Лекция 5: B-деревья (B-trees, k-way merge sort)
Лекция 5: B-деревья (B-trees, k-way merge sort)Лекция 5: B-деревья (B-trees, k-way merge sort)
Лекция 5: B-деревья (B-trees, k-way merge sort)
 
B trees and_b__trees
B trees and_b__treesB trees and_b__trees
B trees and_b__trees
 
CAD: introduction to floorplanning
CAD:  introduction to floorplanningCAD:  introduction to floorplanning
CAD: introduction to floorplanning
 
floor planning
floor planningfloor planning
floor planning
 
Best for b trees
Best for b treesBest for b trees
Best for b trees
 
Examining Mac File Structures
Examining Mac File StructuresExamining Mac File Structures
Examining Mac File Structures
 
17. Trees and Graphs
17. Trees and Graphs17. Trees and Graphs
17. Trees and Graphs
 

Similar to 1.9 b tree

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
MalligaarjunanN
 
B+ tree.pptx
B+ tree.pptxB+ tree.pptx
B+ tree.pptx
Maitri Shah
 
Adbms 22 dynamic multi level index using b and b+ tree
Adbms 22 dynamic multi level index using b  and b+ treeAdbms 22 dynamic multi level index using b  and b+ tree
Adbms 22 dynamic multi level index using b and b+ tree
Vaibhav Khanna
 
btrees.ppt ttttttttttttttttttttttttttttt
btrees.ppt  tttttttttttttttttttttttttttttbtrees.ppt  ttttttttttttttttttttttttttttt
btrees.ppt ttttttttttttttttttttttttttttt
RAtna29
 
4-b-tree.ppt
4-b-tree.ppt4-b-tree.ppt
4-b-tree.ppt
meenamadhuvandhi2
 
Btree
BtreeBtree
Btree
jasscheema
 

Similar to 1.9 b tree (6)

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.pptx
B+ tree.pptxB+ tree.pptx
B+ tree.pptx
 
Adbms 22 dynamic multi level index using b and b+ tree
Adbms 22 dynamic multi level index using b  and b+ treeAdbms 22 dynamic multi level index using b  and b+ tree
Adbms 22 dynamic multi level index using b and b+ tree
 
btrees.ppt ttttttttttttttttttttttttttttt
btrees.ppt  tttttttttttttttttttttttttttttbtrees.ppt  ttttttttttttttttttttttttttttt
btrees.ppt ttttttttttttttttttttttttttttt
 
4-b-tree.ppt
4-b-tree.ppt4-b-tree.ppt
4-b-tree.ppt
 
Btree
BtreeBtree
Btree
 

More from Krish_ver2

5.5 back tracking
5.5 back tracking5.5 back tracking
5.5 back tracking
Krish_ver2
 
5.5 back track
5.5 back track5.5 back track
5.5 back track
Krish_ver2
 
5.5 back tracking 02
5.5 back tracking 025.5 back tracking 02
5.5 back tracking 02
Krish_ver2
 
5.4 randomized datastructures
5.4 randomized datastructures5.4 randomized datastructures
5.4 randomized datastructures
Krish_ver2
 
5.4 randomized datastructures
5.4 randomized datastructures5.4 randomized datastructures
5.4 randomized datastructures
Krish_ver2
 
5.4 randamized algorithm
5.4 randamized algorithm5.4 randamized algorithm
5.4 randamized algorithm
Krish_ver2
 
5.3 dynamic programming 03
5.3 dynamic programming 035.3 dynamic programming 03
5.3 dynamic programming 03
Krish_ver2
 
5.3 dynamic programming
5.3 dynamic programming5.3 dynamic programming
5.3 dynamic programming
Krish_ver2
 
5.3 dyn algo-i
5.3 dyn algo-i5.3 dyn algo-i
5.3 dyn algo-i
Krish_ver2
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
Krish_ver2
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquer
Krish_ver2
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
Krish_ver2
 
5.1 greedyyy 02
5.1 greedyyy 025.1 greedyyy 02
5.1 greedyyy 02
Krish_ver2
 
5.1 greedy
5.1 greedy5.1 greedy
5.1 greedy
Krish_ver2
 
5.1 greedy 03
5.1 greedy 035.1 greedy 03
5.1 greedy 03
Krish_ver2
 
4.4 hashing02
4.4 hashing024.4 hashing02
4.4 hashing02
Krish_ver2
 
4.4 hashing
4.4 hashing4.4 hashing
4.4 hashing
Krish_ver2
 
4.4 hashing ext
4.4 hashing  ext4.4 hashing  ext
4.4 hashing ext
Krish_ver2
 
4.4 external hashing
4.4 external hashing4.4 external hashing
4.4 external hashing
Krish_ver2
 
4.2 bst
4.2 bst4.2 bst
4.2 bst
Krish_ver2
 

More from Krish_ver2 (20)

5.5 back tracking
5.5 back tracking5.5 back tracking
5.5 back tracking
 
5.5 back track
5.5 back track5.5 back track
5.5 back track
 
5.5 back tracking 02
5.5 back tracking 025.5 back tracking 02
5.5 back tracking 02
 
5.4 randomized datastructures
5.4 randomized datastructures5.4 randomized datastructures
5.4 randomized datastructures
 
5.4 randomized datastructures
5.4 randomized datastructures5.4 randomized datastructures
5.4 randomized datastructures
 
5.4 randamized algorithm
5.4 randamized algorithm5.4 randamized algorithm
5.4 randamized algorithm
 
5.3 dynamic programming 03
5.3 dynamic programming 035.3 dynamic programming 03
5.3 dynamic programming 03
 
5.3 dynamic programming
5.3 dynamic programming5.3 dynamic programming
5.3 dynamic programming
 
5.3 dyn algo-i
5.3 dyn algo-i5.3 dyn algo-i
5.3 dyn algo-i
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquer
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
 
5.1 greedyyy 02
5.1 greedyyy 025.1 greedyyy 02
5.1 greedyyy 02
 
5.1 greedy
5.1 greedy5.1 greedy
5.1 greedy
 
5.1 greedy 03
5.1 greedy 035.1 greedy 03
5.1 greedy 03
 
4.4 hashing02
4.4 hashing024.4 hashing02
4.4 hashing02
 
4.4 hashing
4.4 hashing4.4 hashing
4.4 hashing
 
4.4 hashing ext
4.4 hashing  ext4.4 hashing  ext
4.4 hashing ext
 
4.4 external hashing
4.4 external hashing4.4 external hashing
4.4 external hashing
 
4.2 bst
4.2 bst4.2 bst
4.2 bst
 

Recently uploaded

Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 

Recently uploaded (20)

Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 

1.9 b tree

  • 1. Chapter 15 B External Methods – B-Trees
  • 2. © 2004 Pearson Addison-Wesley. All rights reserved 15 B-2 B-Trees • To organize the index file as an external search tree – Use block numbers for child pointers • A child pointer value of –1 is used as the null pointer Figure 15.10a –Figure 15.10a – Blocks organized into a 2-3 tree
  • 3. © 2004 Pearson Addison-Wesley. All rights reserved 15 B-3 B-Trees • If the index file is organized into a 2-3 tree – Each node would contain • Either one or two index records, each of the form <key, pointer> • Three child pointers Figure 15.10b –Figure 15.10b – A single node of the 2-3 tree
  • 4. © 2004 Pearson Addison-Wesley. All rights reserved 15 B-4 B-Trees • An external 2-3 tree is adequate, but an improvement is possible • To improve efficiency – Allow each node to have as many children as possible • In an external environment, the advantage of keeping a search tree short far outweighs the disadvantage of performing extra work at each node • Block size should be the only limiting factor for the number of children
  • 5. © 2004 Pearson Addison-Wesley. All rights reserved 15 B-5 B-Trees • Binary search tree – If a node N has two children, it must contain one key value • 2-3 tree – If a node N has three children, it must contain two key values • General search tree – If a node N has m children, it must contain m – 1 key values
  • 6. © 2004 Pearson Addison-Wesley. All rights reserved 15 B-6 B-Trees Figure 15.11Figure 15.11 a) A node with two children; b) a node with three children; c) a node with m children
  • 7. © 2004 Pearson Addison-Wesley. All rights reserved 15 B-7 B-Trees • B-tree of degree m – All leaves are at the same level – Nodes • Each node contains between m – 1 and m/2 records • Each internal node has one more child than it has records • Exception: The root can contain as few as one record and can have as few as two children – Example • A 2-3 tree is a B-tree of degree 3 – Each node contains between (3-1) = 2 and 3/2 = 1 records.
  • 8. © 2004 Pearson Addison-Wesley. All rights reserved 15 B-8 B-Trees Figure 15.13Figure 15.13 A B-tree of degree 5
  • 9. © 2004 Pearson Addison-Wesley. All rights reserved 15 B-9 B-Trees • Retrieval – Generalized search tree retrieval • Insertion into a B-tree – Step 1: Insert the data record into the data file – Step 2: Insert a corresponding index record into the index file
  • 10. © 2004 Pearson Addison-Wesley. All rights reserved 15 B-10 B-Trees Figure 15.14a and bFigure 15.14a and b The steps for inserting 55
  • 11. © 2004 Pearson Addison-Wesley. All rights reserved 15 B-11 B-Trees Figure 15.14c-eFigure 15.14c-e The steps for inserting 55
  • 12. © 2004 Pearson Addison-Wesley. All rights reserved 15 B-12 B-Trees • Deletion from a B-tree – Step 1: Locate the index record in the index file and delete it from the index file – Step 2: Delete the data record from the data file
  • 13. © 2004 Pearson Addison-Wesley. All rights reserved 15 B-13 B-Trees Figure 15.15a and bFigure 15.15a and b The steps for deleting 73
  • 14. © 2004 Pearson Addison-Wesley. All rights reserved 15 B-14 B-Trees Figure 15.15cFigure 15.15c The steps for deleting 73
  • 15. © 2004 Pearson Addison-Wesley. All rights reserved 15 B-15 B-Trees Figure 15.15dFigure 15.15d The steps for deleting 73
  • 16. © 2004 Pearson Addison-Wesley. All rights reserved 15 B-16 B-Trees Figure 14.15e and fFigure 14.15e and f The steps for deleting 73
  • 17. © 2004 Pearson Addison-Wesley. All rights reserved 15 B-17 Traversals • Accessing only the search key of each record, not the data file – Not efficiently supported by the hashing implementation – Efficiently supported by the B-tree implementation • The search keys can be visited in sorted order by using an inorder traversal of the B-tree • Accessing the entire data record – Not efficiently supported by the B-tree implementation
  • 18. © 2004 Pearson Addison-Wesley. All rights reserved 15 B-18 Multiple Indexing • Advantage – Allows multiple data organizations • Disadvantage – More storage space – Additional overhead for updating each index whenever the data file is modified
  • 19. © 2004 Pearson Addison-Wesley. All rights reserved 15 B-19 Multiple Indexing Figure 15.16Figure 15.16 Multiple index files
  • 20. Chi-Cheng Lin, Winona State University 20 Variations of B-Trees • The fewer nodes are in a B-tree, the better. (Why?) • Problems of B-tree: – It could be only half full • More nodes required • Space wasted – Inorder traversal “jumps” around nodes • B* -Trees: introduced by Donald Knuth • B+ -Trees: introduced by H. Wedekind
  • 21. Chi-Cheng Lin, Winona State University 21 B* -Trees • B* -tree of degree m – All leaves are at the same level – Nodes • Each node contains between m – 1 and (2m – 1)/3 records • Each internal node has one more child than it has records • Exception: The root can contain as few as one record and as many as (2m-2) children – Example • B* -tree of degree 9 – Each node contains between (9 – 1) = 8 and (2×9 – 1)/3 = 5 records.
  • 22. Chi-Cheng Lin, Winona State University 22 B* -Trees • Splitting nodes – When a node overflows, it is not split right away – A split is delayed by redistributing the keys between a node and its sibling – When both a node and its sibling are full, an insertion to the node will split the two nodes into three nodes • A B*-Tree is always two-third full instead of half full  number of nodes in the tree is reduced
  • 23. Chi-Cheng Lin, Winona State University 23 B* -Trees
  • 24. Chi-Cheng Lin, Winona State University 24 B+ -Trees • References to data are only made from the leaves – All index records can be found from the leaves • Two sets of nodes – Index set • Internal nodes • Provides fast access of data – Sequence set • Leaves, linked sequentially • Provides efficient inorder traversal
  • 25. Chi-Cheng Lin, Winona State University 25 B+ -Trees