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

PDF
Tutorial 3 (b tree min heap)
PPT
presentation on b tress. heap trees.hashing
PPTX
Oracle DBA Online Training in India
PDF
Bigtable and Boxwood
PPT
B-link-tree
PPT
Top 10 Oracle SQL tuning tips
PPTX
Network Forensics
PPT
Tpr star tree
Tutorial 3 (b tree min heap)
presentation on b tress. heap trees.hashing
Oracle DBA Online Training in India
Bigtable and Boxwood
B-link-tree
Top 10 Oracle SQL tuning tips
Network Forensics
Tpr star tree

Viewers also liked (9)

ZIP
Algorithm Introduction #18 B-Tree
PDF
Лекция 5: B-деревья (B-trees, k-way merge sort)
PPT
B trees and_b__trees
PPTX
CAD: introduction to floorplanning
PPT
floor planning
PPT
Best for b trees
PPTX
Examining Mac File Structures
PPT
17. Trees and Graphs
Algorithm Introduction #18 B-Tree
Лекция 5: B-деревья (B-trees, k-way merge sort)
B trees and_b__trees
CAD: introduction to floorplanning
floor planning
Best for b trees
Examining Mac File Structures
17. Trees and Graphs
Ad

Similar to 1.9 b tree (7)

PPTX
Data structures trees - B Tree & B+Tree.pptx
PPTX
B+ tree.pptx
PPTX
Adbms 22 dynamic multi level index using b and b+ tree
PPT
btrees.ppt ttttttttttttttttttttttttttttt
PPT
M.E - Computer Science and Engineering-Data structure B tree
PPT
4-b-tree.ppt
PPT
Btree
Data structures trees - B Tree & B+Tree.pptx
B+ tree.pptx
Adbms 22 dynamic multi level index using b and b+ tree
btrees.ppt ttttttttttttttttttttttttttttt
M.E - Computer Science and Engineering-Data structure B tree
4-b-tree.ppt
Btree
Ad

More from Krish_ver2 (20)

PPT
5.5 back tracking
PPT
5.5 back track
PPT
5.5 back tracking 02
PPT
5.4 randomized datastructures
PPT
5.4 randomized datastructures
PPT
5.4 randamized algorithm
PPT
5.3 dynamic programming 03
PPT
5.3 dynamic programming
PPT
5.3 dyn algo-i
PPT
5.2 divede and conquer 03
PPT
5.2 divide and conquer
PPT
5.2 divede and conquer 03
PPT
5.1 greedyyy 02
PPT
5.1 greedy
PPT
5.1 greedy 03
PPT
4.4 hashing02
PPT
4.4 hashing
PPT
4.4 hashing ext
PPT
4.4 external hashing
PPT
4.2 bst
5.5 back tracking
5.5 back track
5.5 back tracking 02
5.4 randomized datastructures
5.4 randomized datastructures
5.4 randamized algorithm
5.3 dynamic programming 03
5.3 dynamic programming
5.3 dyn algo-i
5.2 divede and conquer 03
5.2 divide and conquer
5.2 divede and conquer 03
5.1 greedyyy 02
5.1 greedy
5.1 greedy 03
4.4 hashing02
4.4 hashing
4.4 hashing ext
4.4 external hashing
4.2 bst

Recently uploaded (20)

PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Cell Types and Its function , kingdom of life
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
RMMM.pdf make it easy to upload and study
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Module 4: Burden of Disease Tutorial Slides S2 2025
Chinmaya Tiranga quiz Grand Finale.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
A systematic review of self-coping strategies used by university students to ...
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Anesthesia in Laparoscopic Surgery in India
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Final Presentation General Medicine 03-08-2024.pptx
Final Presentation General Medicine 03-08-2024.pptx
Cell Types and Its function , kingdom of life
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Cell Structure & Organelles in detailed.
RMMM.pdf make it easy to upload and study
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
O7-L3 Supply Chain Operations - ICLT Program
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
O5-L3 Freight Transport Ops (International) V1.pdf
human mycosis Human fungal infections are called human mycosis..pptx
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx

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