SlideShare a Scribd company logo
1 of 29
0
Course Outline
n Introduction and Algorithm Analysis (Ch. 2)
n Hash Tables: dictionary data structure (Ch. 5)
n Heaps: priority queue data structures (Ch. 6)
n Balanced Search Trees: Splay Trees (Ch. 4.5)
n Union-Find data structure (Ch. 8.1–8.5)
n Graphs: Representations and basic algorithms
 Topological Sort (Ch. 9.1-9.2)
 Minimum spanning trees (Ch. 9.5)
 Shortest-path algorithms (Ch. 9.3.2)
n B-Trees: External-Memory data structures (Ch. 4.7)
n kD-Trees: Multi-Dimensional data structures (Ch. 12.6)
n Misc.: Streaming data, randomization
1
B-Trees
n B-Trees are designed to minimize I/O operations
n Large database stored in secondary memory (disks, cloud)
 Too large for main memory
 Non-uniform data access cost: memory vs. disk
 Similar considerations for cache vs. main memory
2
B-Trees
n Data access costs vary significantly
 Disk access 103 --105 times slower than silicon memory.
 Somewhat outdated numbers, but illustrative:
 Disks rotate at about 7200 RPM; typical range 5K-15K.
 One rotation takes 8.33 ms, which is about 5 orders slower than a 50
nsec access for current silicon memory.
3
B-Trees
n To amortize huge disk access cost, data transferred in large
chunks.
 Information (e.g. set of key values) chunked into large "pages”
laid out consecutively within each disk cylinder
 Typical page size: 211 to 214 bytes (2K-16K)
 Think of B-Tree as a BST with very fat nodes
n Processing an entire page takes less time than to fetch it
n So, in disk-bound data structures, we consider two factors
separately:
 number of disk accesses,
 the CPU time.
4
B-Trees
 B-Tree algorithms operate at the granularity of pages. I.e., the
unit operations READ or WRITE a page
 The main memory can accommodate only so many pages, so
older pages will be flushed out as new ones are fetched.
5
B-Trees
 To optimize the number of page accesses, we choose the size
of the B-Tree node to match the page size.
 That is, each node will store keys for about 50-2000 items,
and will have the similar branching factor
 With a branching factor of 1001 (1000 keys per node), 1
billion keys can be accessed by a tree of height 2.
 Just 2 disk accesses!
6
B-Trees: an example
7
B-Tree: Structural Details
8
B-Tree: Formal Definitions
9
B-Tree: Formal Definitions
10
B-Tree: Properties
n Simplest B-tree when t=2 (also called 2-3-4 trees)
n Height of a B-tree: h <= logt (n + 1)/2
11
B-Tree: Height Bound
12
B-Tree: Searching for a Key
• Root node always in main
memory, so no disk-access
required there.
• But access to any other node
requires disk-read.
13
B-Tree: Inserting a key k
n Search for the leaf node to insert k.
 What happens if that node is full (2t-1 keys)
 All B-Tree nodes must be at same depth and have between t-
1 and 2t-1 keys.
 For instance, insert key I into the leaf [J, K, L]
14
B-Tree: Splitting a node
n If insert leaf is full, we split it around its middle tth key.
 Median key moves to the parent, and
 Two new children, each with t-1 keys formed.
 If parent becomes full, recursively split upwards
15
B-Tree-Split-Child
• y is the ith child of x, and is the node being split.
• y originally has 2t children, and is reduced to t (and t-1 keys) by this
operation.
• z adopts the t largest children of y, and z becomes a new child of x,
positioned just after y in x's table.
• The median key of y moves up to x, separating y and z.
16
B-Tree-Insert
17
B-Tree: Splitting a Node
18
B-Tree-Insert: main routine
• 1st while loop = x is a leaf.
• When x non-leaf, insert into
appropriate leaf in the sub-tree
rooted at x.
• 2nd while loop determines the child
of x to descend to.
• The if condition checks if that child
is a full node.
• If full, B_TREE_SPLIT splits it into
two non-full nodes, and the next if
determines which of the children
to descend to.
19
B-Tree-Insert: Illustration
20
B-Tree-Insert: Illustration
21
B-Trees: Insert Complexity
n The number of disk accesses by B-TREE-INSERT is
O(h): only O(1) disk read or writes between calls to B-
TREE-NONFULL.
n The total CPU time is O(t h) = O(t logt n).
22
B-Trees: Deleting a key
n Deleted key may be in a non-leaf node.
n If the size of a node drops below t-1 after deletion, fix it.
n Suppose we from sub-tree rooted at x.
n We ensure that when B-TREE-DELETE is called on a node x,
the number of keys in x is at least t.
n This allows us to perform deletion in one pass, without backing
up.
23
B-Trees: Deleting a key (Complicated!)
n If k is in leaf-node x, delete k from x.
n If k is in non-leaf node x, do:
 if the child y that precedes k in node x has t or more keys, then find
predecessor k' of k in sub-tree rooted at y. Recursively delete k', and
replace k with k' in x.
 Symmetrically, if child z that follows k in node x has >= t keys, find the
successor k' of k in sub-tree rooted at z. Recursively delete k', and replace
k with k' in x.
 Otherwise, if both y and z have only t-1 keys, merge k and all of z into y so
that x loses both k and the pointer to z, and y now has 2t-1 keys. Free z
and recursively delete k from y.
24
B-Trees: Deleting a key (Complicated!)
n If the key k is not present in node x,
 determine the root ci(x) of the appropriate sub-tree containing
k.
 If ci(x) has only t-1 keys, execute steps (3a) or (3b) to
guarantee we descend to a node with >= t keys.
 Then finish by recursive call on appropriate child of x.
 3a. If ci(x) has only t-1 keys but has an immediate sibling with t or more
keys, give ci(x) an extra key by moving a key from x down to ci(x), moving a
key from ci(x)'s immediate left or right sibling up into x, and moving the
appropriate child pointer from the sibling into ci(x).
 3b. If ci(x) and both of ci(x)'s immediate siblings have t-1 keys, merge ci(x)
with one sibling, which involves moving a key from x down into the new
merged node to become the median key for that node.
25
B-Tree Deletion: Illustration
26
B-Tree Deletion: Illustration
27
B-Tree Deletion: Illustration
28
B-Tree: Deletion Complexity
n Also O(h) disk accesses and O(t logt n) CPU.

More Related Content

Similar to BTree.pptx

Presentation on b trees [autosaved]
Presentation on b trees [autosaved]Presentation on b trees [autosaved]
Presentation on b trees [autosaved]
AKASHKUMAR1542
 
lecture 13
lecture 13lecture 13
lecture 13
sajinsc
 
5220191CS146 Data Structures and AlgorithmsC.docx
5220191CS146 Data Structures and AlgorithmsC.docx5220191CS146 Data Structures and AlgorithmsC.docx
5220191CS146 Data Structures and AlgorithmsC.docx
fredharris32
 
lecture10 date structure types of graph and terminology
lecture10 date structure types of graph and terminologylecture10 date structure types of graph and terminology
lecture10 date structure types of graph and terminology
KamranAli649587
 

Similar to BTree.pptx (20)

7.tree
7.tree7.tree
7.tree
 
PAM.ppt
PAM.pptPAM.ppt
PAM.ppt
 
Trees
TreesTrees
Trees
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Presentation on b trees [autosaved]
Presentation on b trees [autosaved]Presentation on b trees [autosaved]
Presentation on b trees [autosaved]
 
15-btrees.ppt
15-btrees.ppt15-btrees.ppt
15-btrees.ppt
 
UNIT II.ppt
UNIT II.pptUNIT II.ppt
UNIT II.ppt
 
Lecture notes data structures tree
Lecture notes data structures   treeLecture notes data structures   tree
Lecture notes data structures tree
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structure
 
lecture 13
lecture 13lecture 13
lecture 13
 
Red Black Trees
Red Black TreesRed Black Trees
Red Black Trees
 
7 chapter4 trees_binary
7 chapter4 trees_binary7 chapter4 trees_binary
7 chapter4 trees_binary
 
5220191CS146 Data Structures and AlgorithmsC.docx
5220191CS146 Data Structures and AlgorithmsC.docx5220191CS146 Data Structures and AlgorithmsC.docx
5220191CS146 Data Structures and AlgorithmsC.docx
 
210 trees
210 trees210 trees
210 trees
 
210 trees5
210 trees5210 trees5
210 trees5
 
Balance tree. Short overview
Balance tree. Short overviewBalance tree. Short overview
Balance tree. Short overview
 
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
 
Unit 3.ppt
Unit 3.pptUnit 3.ppt
Unit 3.ppt
 
lecture10 date structure types of graph and terminology
lecture10 date structure types of graph and terminologylecture10 date structure types of graph and terminology
lecture10 date structure types of graph and terminology
 
Binary trees1
Binary trees1Binary trees1
Binary trees1
 

Recently uploaded

Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
amitlee9823
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
MarinCaroMartnezBerg
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
AroojKhan71
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
amitlee9823
 
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
amitlee9823
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
amitlee9823
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
amitlee9823
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night StandCall Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 

Recently uploaded (20)

Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interaction
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and Milvus
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night StandCall Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptx
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
 

BTree.pptx

  • 1. 0 Course Outline n Introduction and Algorithm Analysis (Ch. 2) n Hash Tables: dictionary data structure (Ch. 5) n Heaps: priority queue data structures (Ch. 6) n Balanced Search Trees: Splay Trees (Ch. 4.5) n Union-Find data structure (Ch. 8.1–8.5) n Graphs: Representations and basic algorithms  Topological Sort (Ch. 9.1-9.2)  Minimum spanning trees (Ch. 9.5)  Shortest-path algorithms (Ch. 9.3.2) n B-Trees: External-Memory data structures (Ch. 4.7) n kD-Trees: Multi-Dimensional data structures (Ch. 12.6) n Misc.: Streaming data, randomization
  • 2. 1 B-Trees n B-Trees are designed to minimize I/O operations n Large database stored in secondary memory (disks, cloud)  Too large for main memory  Non-uniform data access cost: memory vs. disk  Similar considerations for cache vs. main memory
  • 3. 2 B-Trees n Data access costs vary significantly  Disk access 103 --105 times slower than silicon memory.  Somewhat outdated numbers, but illustrative:  Disks rotate at about 7200 RPM; typical range 5K-15K.  One rotation takes 8.33 ms, which is about 5 orders slower than a 50 nsec access for current silicon memory.
  • 4. 3 B-Trees n To amortize huge disk access cost, data transferred in large chunks.  Information (e.g. set of key values) chunked into large "pages” laid out consecutively within each disk cylinder  Typical page size: 211 to 214 bytes (2K-16K)  Think of B-Tree as a BST with very fat nodes n Processing an entire page takes less time than to fetch it n So, in disk-bound data structures, we consider two factors separately:  number of disk accesses,  the CPU time.
  • 5. 4 B-Trees  B-Tree algorithms operate at the granularity of pages. I.e., the unit operations READ or WRITE a page  The main memory can accommodate only so many pages, so older pages will be flushed out as new ones are fetched.
  • 6. 5 B-Trees  To optimize the number of page accesses, we choose the size of the B-Tree node to match the page size.  That is, each node will store keys for about 50-2000 items, and will have the similar branching factor  With a branching factor of 1001 (1000 keys per node), 1 billion keys can be accessed by a tree of height 2.  Just 2 disk accesses!
  • 11. 10 B-Tree: Properties n Simplest B-tree when t=2 (also called 2-3-4 trees) n Height of a B-tree: h <= logt (n + 1)/2
  • 13. 12 B-Tree: Searching for a Key • Root node always in main memory, so no disk-access required there. • But access to any other node requires disk-read.
  • 14. 13 B-Tree: Inserting a key k n Search for the leaf node to insert k.  What happens if that node is full (2t-1 keys)  All B-Tree nodes must be at same depth and have between t- 1 and 2t-1 keys.  For instance, insert key I into the leaf [J, K, L]
  • 15. 14 B-Tree: Splitting a node n If insert leaf is full, we split it around its middle tth key.  Median key moves to the parent, and  Two new children, each with t-1 keys formed.  If parent becomes full, recursively split upwards
  • 16. 15 B-Tree-Split-Child • y is the ith child of x, and is the node being split. • y originally has 2t children, and is reduced to t (and t-1 keys) by this operation. • z adopts the t largest children of y, and z becomes a new child of x, positioned just after y in x's table. • The median key of y moves up to x, separating y and z.
  • 19. 18 B-Tree-Insert: main routine • 1st while loop = x is a leaf. • When x non-leaf, insert into appropriate leaf in the sub-tree rooted at x. • 2nd while loop determines the child of x to descend to. • The if condition checks if that child is a full node. • If full, B_TREE_SPLIT splits it into two non-full nodes, and the next if determines which of the children to descend to.
  • 22. 21 B-Trees: Insert Complexity n The number of disk accesses by B-TREE-INSERT is O(h): only O(1) disk read or writes between calls to B- TREE-NONFULL. n The total CPU time is O(t h) = O(t logt n).
  • 23. 22 B-Trees: Deleting a key n Deleted key may be in a non-leaf node. n If the size of a node drops below t-1 after deletion, fix it. n Suppose we from sub-tree rooted at x. n We ensure that when B-TREE-DELETE is called on a node x, the number of keys in x is at least t. n This allows us to perform deletion in one pass, without backing up.
  • 24. 23 B-Trees: Deleting a key (Complicated!) n If k is in leaf-node x, delete k from x. n If k is in non-leaf node x, do:  if the child y that precedes k in node x has t or more keys, then find predecessor k' of k in sub-tree rooted at y. Recursively delete k', and replace k with k' in x.  Symmetrically, if child z that follows k in node x has >= t keys, find the successor k' of k in sub-tree rooted at z. Recursively delete k', and replace k with k' in x.  Otherwise, if both y and z have only t-1 keys, merge k and all of z into y so that x loses both k and the pointer to z, and y now has 2t-1 keys. Free z and recursively delete k from y.
  • 25. 24 B-Trees: Deleting a key (Complicated!) n If the key k is not present in node x,  determine the root ci(x) of the appropriate sub-tree containing k.  If ci(x) has only t-1 keys, execute steps (3a) or (3b) to guarantee we descend to a node with >= t keys.  Then finish by recursive call on appropriate child of x.  3a. If ci(x) has only t-1 keys but has an immediate sibling with t or more keys, give ci(x) an extra key by moving a key from x down to ci(x), moving a key from ci(x)'s immediate left or right sibling up into x, and moving the appropriate child pointer from the sibling into ci(x).  3b. If ci(x) and both of ci(x)'s immediate siblings have t-1 keys, merge ci(x) with one sibling, which involves moving a key from x down into the new merged node to become the median key for that node.
  • 29. 28 B-Tree: Deletion Complexity n Also O(h) disk accesses and O(t logt n) CPU.