SlideShare a Scribd company logo
File Processing & Organization
Course No: 5901227-3
Lecture 7
B-Trees (Continued)
Inserting a key into a B-tree in a single
pass down the tree
• The B-TREE-INSERT procedure uses B-TREE-SPLIT-CHILD to
guarantee that the recursion never descends to a full node.
B-TREE-INSERT(T, k)
1 r ← root[T]
2 if n[r] = 2t - 1
3 then s ← ALLOCATE-NODE()
4 root[T] ← s
5 leaf[s] ← FALSE
6 n[s] ← 0
7 c1[s] ← r
8 B-TREE-SPLIT-CHILD(s, 1, r)
9 B-TREE-INSERT-NONFULL(s, k)
10 else B-TREE-INSERT-NONFULL(r, k)
• Lines 3-9 handle the case in which the root node r
is full: the root is split and a new node s (having
two children) becomes the root. Splitting the root
is the only way to increase the height of a B-tree.
Figure 1 illustrates this case.
• The procedure finishes by calling BTREE-INSERT-
NONFULL to perform the insertion of key k in the
tree rooted at the nonfull root node.
Figure 1
• Splitting the root with t = 4. Root node r is split in two, and a
new root node s is created. The new root contains the median
key of r and has the two halves of r as children.
• The B-tree grows in height by one when the root is split.
B-TREE-INSERT-NONFULL
• B-TREE-INSERT-NONFULL(x, k)
1 i ← n[x]
2 if leaf[x]
3 then while i ≥ 1 and k < keyi[x]
4 do keyi+1[x] ← keyi[x]
5 i ← i - 1
6 keyi+1[x] ← k
7 n[x] ← n[x] + 1
8 DISK-WRITE(x)
9 else while i ≥ 1 and k < keyi[x]
10 do i ← i - 1
11 i ← i + 1
12 DISK-READ(ci[x])
13 if n[ci[x]] = 2t - 1
14 then B-TREE-SPLIT-CHILD(x, i, ci[x])
15 if k> keyi[x]
16 then i ← i + 1
17 B-TREE-INSERT-NONFULL(ci[x], k)
• Lines 3-8 handle the case in which x is a leaf node
by inserting key k into x. If x is not a leaf node,
then we must insert k into the appropriate leaf
node in the subtree rooted at internal node x.
• In this case, lines 9-11 determine the child of x to
which the recursion descends.
• Lines 13-16 guarantee that the procedure never
recurses to a full node.
• Line 17 then recurses to insert k into the
appropriate subtree.
Deleting a key from a B-tree
• Just as we had to ensure that a node didn't
get too big due to insertion, we must ensure
that a node doesn't get too small during
deletion
Deleting a key from a B-tree
• Delete key B from a B-Tree with t=3.
D G
A B C E F H I
Deleting a key from a B-tree
We want to delete key F from a B-Tree
with t =3.
D G
A B C E F H I
Deleting a key from a B-tree
We want to delete key F from a B-Tree
with t =3.
G
A B C D E F H I
Deleting a key from a B-tree
We want to delete key F from a B-Tree
with t =3.
C G
A B D E F H I
Deleting a key from a B-tree
We want to delete key S from a B-Tree
with t=3.
Q T
OP R S U X
Deleting a key from a B-tree
We want to delete key S from a B-Tree
with t=3.
Q T
OP R S T U X
Deleting a key from a B-tree
Q U
O P R S T W V
Deleting a key from a B-tree
We want to delete key U from a B-Tree
with t=3.
Q T
O P R S W V
Deleting a key from a B-tree
• We want to delete I from a B-Tree with t =3.
I H
G M J K L O P
Deleting a key from a B-tree
• We want to delete I from a B-Tree with t =3.
J H
G M K L O P
Deleting a key from a B-tree
• We want to delete U from a B-Tree with t =3.
R U X
P Q ST V W Y Z
Deleting a key from a B-tree
• We want to delete U from a B-Tree with t =3.
R X
P Q S T V W Y Z

More Related Content

PPTX
Factoring quadratics ex 5
ZIP
AA Section 5-7
PPT
4.3b & 4 Rr
PDF
Cube and cube roots converted-converted
PPTX
Alg1 review of writing equations of lines
PPTX
Sign Sign 2
PDF
The twin prime counting function
PPT
Calc 5.1a
Factoring quadratics ex 5
AA Section 5-7
4.3b & 4 Rr
Cube and cube roots converted-converted
Alg1 review of writing equations of lines
Sign Sign 2
The twin prime counting function
Calc 5.1a

What's hot (19)

DOCX
Smu bca sem 3 fall 2015 assignments
PPS
Addsub poly
PPT
R merge-tutorial
DOCX
Factoring polynomials with common monomial factor
DOCX
Smu bca sem 3 spring 2016 assignments
PPT
5.5 roots of real numbers
PDF
Completing the square class notes
PDF
Pascal Triangle
PDF
4 ESO Academics - Unit 01 - Exercises 1.3.
PPT
Chapter4.3
PPTX
Edu 290 ppt 2
PPTX
Edu 290 ppt 1
PDF
Chirp_Mass
PPTX
Alegebra Powers Substitution
DOCX
Ch 1 review stations (Classwork)
PPT
Chapter 4.3b - GCF with variables
PPT
The Max Cut Problem
PPT
Expand brackets 1
PDF
Can you count on your computer?
Smu bca sem 3 fall 2015 assignments
Addsub poly
R merge-tutorial
Factoring polynomials with common monomial factor
Smu bca sem 3 spring 2016 assignments
5.5 roots of real numbers
Completing the square class notes
Pascal Triangle
4 ESO Academics - Unit 01 - Exercises 1.3.
Chapter4.3
Edu 290 ppt 2
Edu 290 ppt 1
Chirp_Mass
Alegebra Powers Substitution
Ch 1 review stations (Classwork)
Chapter 4.3b - GCF with variables
The Max Cut Problem
Expand brackets 1
Can you count on your computer?
Ad

Similar to Fileprocessing lec-7 (20)

PPT
b-tree.ppt
PPTX
PPTX
Lecture_10 - Revised.pptx
PDF
PEA 305.pdf
PDF
Chapter 09-Trees
PPTX
BTree.pptx
PPTX
Lecture 11 data structures and algorithms
PPT
bst-class-220902051152-cdddddddddddddddddd5e6c70f.ppt
PPT
Binary search trees
PPT
Binary Search Tree
PPT
lecture10 date structure types of graph and terminology
PDF
Form 5 Additional Maths Note
PDF
PPTX
10.m way search tree
PPT
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
PPT
Tree_Traversals.pptmmmmmmmmmmmmmmmmmmmmm
PDF
DSA (Data Structure and Algorithm) Questions
DOCX
(a) There are three ways to traverse a binary tree pre-order, in-or.docx
b-tree.ppt
Lecture_10 - Revised.pptx
PEA 305.pdf
Chapter 09-Trees
BTree.pptx
Lecture 11 data structures and algorithms
bst-class-220902051152-cdddddddddddddddddd5e6c70f.ppt
Binary search trees
Binary Search Tree
lecture10 date structure types of graph and terminology
Form 5 Additional Maths Note
10.m way search tree
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
Tree_Traversals.pptmmmmmmmmmmmmmmmmmmmmm
DSA (Data Structure and Algorithm) Questions
(a) There are three ways to traverse a binary tree pre-order, in-or.docx
Ad

More from sawsan slii (13)

PPTX
Ch1 traditional it and cloud
PPTX
Aws principle services: IAM,VPC, EC2, Cloudwatch
PPTX
Introduction to exploring hci
PPTX
Design principles
PPTX
Introduction hci
PPTX
Ch1 traditional it and cloud
PPTX
Cache mapping exercises
PPTX
evaluation techniques in HCI
PPTX
Evaluation techniques in HCI
PDF
Ajax and xml
PPT
UCD and low-fidelity prototyping
PPT
Web forms and server side scripting
PPT
Web server administration
Ch1 traditional it and cloud
Aws principle services: IAM,VPC, EC2, Cloudwatch
Introduction to exploring hci
Design principles
Introduction hci
Ch1 traditional it and cloud
Cache mapping exercises
evaluation techniques in HCI
Evaluation techniques in HCI
Ajax and xml
UCD and low-fidelity prototyping
Web forms and server side scripting
Web server administration

Recently uploaded (20)

PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
Lecture Notes Electrical Wiring System Components
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPT
Project quality management in manufacturing
PPTX
web development for engineering and engineering
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
DOCX
573137875-Attendance-Management-System-original
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Lecture Notes Electrical Wiring System Components
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Project quality management in manufacturing
web development for engineering and engineering
Foundation to blockchain - A guide to Blockchain Tech
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Embodied AI: Ushering in the Next Era of Intelligent Systems
Arduino robotics embedded978-1-4302-3184-4.pdf
CYBER-CRIMES AND SECURITY A guide to understanding
CH1 Production IntroductoryConcepts.pptx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
UNIT 4 Total Quality Management .pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
573137875-Attendance-Management-System-original
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd

Fileprocessing lec-7

  • 1. File Processing & Organization Course No: 5901227-3 Lecture 7 B-Trees (Continued)
  • 2. Inserting a key into a B-tree in a single pass down the tree • The B-TREE-INSERT procedure uses B-TREE-SPLIT-CHILD to guarantee that the recursion never descends to a full node. B-TREE-INSERT(T, k) 1 r ← root[T] 2 if n[r] = 2t - 1 3 then s ← ALLOCATE-NODE() 4 root[T] ← s 5 leaf[s] ← FALSE 6 n[s] ← 0 7 c1[s] ← r 8 B-TREE-SPLIT-CHILD(s, 1, r) 9 B-TREE-INSERT-NONFULL(s, k) 10 else B-TREE-INSERT-NONFULL(r, k)
  • 3. • Lines 3-9 handle the case in which the root node r is full: the root is split and a new node s (having two children) becomes the root. Splitting the root is the only way to increase the height of a B-tree. Figure 1 illustrates this case. • The procedure finishes by calling BTREE-INSERT- NONFULL to perform the insertion of key k in the tree rooted at the nonfull root node.
  • 4. Figure 1 • Splitting the root with t = 4. Root node r is split in two, and a new root node s is created. The new root contains the median key of r and has the two halves of r as children. • The B-tree grows in height by one when the root is split.
  • 5. B-TREE-INSERT-NONFULL • B-TREE-INSERT-NONFULL(x, k) 1 i ← n[x] 2 if leaf[x] 3 then while i ≥ 1 and k < keyi[x] 4 do keyi+1[x] ← keyi[x] 5 i ← i - 1 6 keyi+1[x] ← k 7 n[x] ← n[x] + 1 8 DISK-WRITE(x) 9 else while i ≥ 1 and k < keyi[x]
  • 6. 10 do i ← i - 1 11 i ← i + 1 12 DISK-READ(ci[x]) 13 if n[ci[x]] = 2t - 1 14 then B-TREE-SPLIT-CHILD(x, i, ci[x]) 15 if k> keyi[x] 16 then i ← i + 1 17 B-TREE-INSERT-NONFULL(ci[x], k)
  • 7. • Lines 3-8 handle the case in which x is a leaf node by inserting key k into x. If x is not a leaf node, then we must insert k into the appropriate leaf node in the subtree rooted at internal node x. • In this case, lines 9-11 determine the child of x to which the recursion descends. • Lines 13-16 guarantee that the procedure never recurses to a full node. • Line 17 then recurses to insert k into the appropriate subtree.
  • 8. Deleting a key from a B-tree • Just as we had to ensure that a node didn't get too big due to insertion, we must ensure that a node doesn't get too small during deletion
  • 9. Deleting a key from a B-tree • Delete key B from a B-Tree with t=3. D G A B C E F H I
  • 10. Deleting a key from a B-tree We want to delete key F from a B-Tree with t =3. D G A B C E F H I
  • 11. Deleting a key from a B-tree We want to delete key F from a B-Tree with t =3. G A B C D E F H I
  • 12. Deleting a key from a B-tree We want to delete key F from a B-Tree with t =3. C G A B D E F H I
  • 13. Deleting a key from a B-tree We want to delete key S from a B-Tree with t=3. Q T OP R S U X
  • 14. Deleting a key from a B-tree We want to delete key S from a B-Tree with t=3. Q T OP R S T U X
  • 15. Deleting a key from a B-tree Q U O P R S T W V
  • 16. Deleting a key from a B-tree We want to delete key U from a B-Tree with t=3. Q T O P R S W V
  • 17. Deleting a key from a B-tree • We want to delete I from a B-Tree with t =3. I H G M J K L O P
  • 18. Deleting a key from a B-tree • We want to delete I from a B-Tree with t =3. J H G M K L O P
  • 19. Deleting a key from a B-tree • We want to delete U from a B-Tree with t =3. R U X P Q ST V W Y Z
  • 20. Deleting a key from a B-tree • We want to delete U from a B-Tree with t =3. R X P Q S T V W Y Z