SlideShare a Scribd company logo
1 of 28
Presented By:
Fatimah M. Alqadheeb
218002332
Content
 Introduction
 B-Tree Properties
 The Height of a B-Tree
 Basic Operation in a B-Tree
 Inserting
 Deleting
 Time Complexity
 Usage of B-Tree
 References
2
Quote of the Day!
3
Introduction:
 In case of too large data that could not be fit in a main memory
 So, that’s require to access the disk multiple of times
 Accessing the disk requires long time
 We need to reduce the number of disk access!
 The solution is to use the B-Tree, which gives more branches with
less height
4
B-Tree
 B-Tree: is a balanced rooted tree whose root is T root.
 Properties of B- Tree:
1. For every node x in B- Tree:
a. x.n the number of keys in x node
b. The x.n keys themselves x. key1, x. key2, …, x. keyn (increasing
order)
c. x.leaf is a Boolean value that is true if x is a leaf & false if x is an
internal node
x.n
x. 𝒌𝒆𝒚 𝟏 x. 𝒌𝒆𝒚 𝟐 x. 𝒌𝒆𝒚 𝟑
5
10 16
1 2 3
9 11 12 13 14 17 20
Cont. Properties of B- Tree:
…
1. Each internal node x also contains x.n+1 pointers x. 𝒄 𝟏, x. 𝒄 𝟐, …,
x. 𝒄 𝒙.𝒏+𝟏
2. The keys x. 𝒌𝒆𝒚𝐢 separates the ranges of keys in the subtree x. 𝒄𝐢
as 𝐤 𝐢 <= x. 𝒌𝒆𝒚𝐢 <= x. 𝒌𝒆𝒚𝐢+𝟏<= …<= x. 𝒌𝒆𝒚 𝒏 <=x. 𝒌𝒆𝒚 𝒏+𝟏
1 2 3
…
x. 𝒄 𝟏 x. 𝒄 𝟐 x. 𝒄 𝟑
6
4. All the leaves have the same depth which is the tree’s height h
o h <= 𝑙𝑜𝑔𝑡
𝑛+1
2
5. Nodes have upper and lower bounds of the keys they can contain,
the minimum degree of the B- Tree is t >= 2
a. Every node other than the root must have at least t-1 keys
o The internal node has at least t children
b. Every node may contain the root at most 2t-1 keys
o The internal node has at most 2t children
Cont. Properties of B- Tree:
7
Basic Operation in a B- Tree
 Create
 Search
 Insert
 Delete
8
Insert a Key into a B- Tree
when x is a leaf node
when x has children decide
which one to go !
when child is full => splitting
9
Example 1: (Insertion into B- Tree)
 Insert key = 2 ?
7 13 16 24
1 3 4 5 10 11 14 15 18 19 20 21 22 25 26
10
 Insert key = 2?
o i=x.n = 4
o if x.leaf? => false
o else while(i >= 1 and 2 < x.𝑘𝑒𝑦𝑖)
• i=4 >1 && 2<24 => i=4-1 = 3
• i=3>1 && 2<16 => i=3-1=2
• i=2 && 2<13 => i=2-1=1
• i=1 && 2<7 => i=1-1=0
o Out from while loop i=0+1=1
o DISK-READ (x. 𝑐1)
o if x. 𝑐1 .n == 2t-1? x. 𝑐1 .n =4 = 5 it’s not full!
o B-TREE-INSERT-NONFULL(x. 𝑐1 .n,2)
x
11
 Insert key = 2?
o i=x.n = 4
o if x.leaf? => true
o while(i >= 1 and 2 < x.𝑘𝑒𝑦𝑖)
• i=4 >1 && 2<5 => x.𝑘𝑒𝑦4+1=5 , i=3
• i=3>1 && 2<4 => x.𝑘𝑒𝑦3+1=4 , i=2
• i=2 && 2<3 => x.𝑘𝑒𝑦2+1=3 , i=1
• i=1 && 2<1 => Out from while loop i=1
o x.𝑘𝑒𝑦1+1=2 , x.n = 5
o DISK-WRITE(x)
x
12
Example 1: (Insertion into B- Tree)
7 13 16 24
1 2 3 4 5 10 11 14 15 18 19 20 21 22 25 26
x.𝑘𝑒𝑦2
 The B-Tree after inserting key =2
13
Example 2: (Insertion into B- Tree)
7 13 16 24
1 2 3 4 5 10 11 14 15 18 19 20 21 22 25 26
 Insert key = 17 ?
14
 Insert key = 17?
o i=x.n = 4
o if x.leaf? => false
o else while(i >= 1 and 2 < x.𝑘𝑒𝑦𝑖)
• i=4 >1 && 17<24 => i=4-1 = 3
• i=3>1 && 17<16 => Out from while loop i=3+1=4
• DISK-READ (x. 𝑐4)
o if x. 𝑐1 .n == 2t-1? x. 𝑐1 .n = 5 = 5 it’s full!
o B-TREE-SPLIT-CHILD(x. 𝑐4, 4)
x
15
Example 2: (Insertion into B- Tree)
7 13 16 24
1 3 4 5 10 11 14 15 18 19 20 21 22 25 26
20
10 11 10 11
16
Example 2: (Insertion into B- Tree)
 The new B-Tree after splitting
7 13 16 20 24
1 2 3 4 5 10 11 14 15 18 19 25 2621 22
17
 Insert key = 17?
o if k > x.𝑘𝑒𝑦4 ? => 17 > 22
o B-TREE-INSERT-NONFULL(x. 𝑐4 .n, 17)
o …
x.𝑘𝑒𝑦2
 The B-Tree after inserting key = 17
18
Deleting a key in a B-Tree
1. If the key k is in node x and x is a leaf, delete the key k from x.
2. If the key k is in node x and x is an internal node, do the
following:
a. If the child y that precedes k in node x has at least t keys, then
find the predecessor of k in the subtree rooted at y. then
delete k and replace k by its predecessor
b. If y has fewer than t keys, then, look at the next z child that
follows y child if z has at least t keys, then find the successor
of k then delete the k and replace it with its successor.
c. If both y and z have only t-1 keys, merge k with all keys in z
to the child y, then delete the k from y
19
Deleting a key in a B-Tree
3. If the key k is not present in internal node x, determine the
root x.𝒄𝒊 of the appropriate subtree that must contain k. Note:
necessary to guarantee that we descend to a node containing at
least t keys, do the following:
a. If x.𝒄𝒊 has only t -1 keys but has an immediate sibling with at
least t keys, give x.𝑐𝑖 an extra key by moving a key from x
down into x.𝑐𝑖, moving a key from x.𝑐𝑖’s immediate left or
right sibling up into x. then delete the key
b. If x.𝑐𝑖 and both of x.𝑐𝑖 ’s immediate siblings have t -1 keys,
merge 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, then delete the key
20
Example 1: Deleting a key in a B-Tree
 Delete key 6:
 Key 6 is in a leaf node, this is Case 1 , Just delete it
21
t=3
Example 2: Deleting a key in a B-Tree
 Delete key 13:
 Key 6 is in a leaf node, this is Case 2,
22
Example 2: Deleting a key in a B-Tree
 Delete key 13:
 Key 6 is in a leaf node, this is Case 2,
 Case 2.a delete k and find its predecessor and place it in key’s
position
23
Example 2: Deleting a key in a B-Tree
 Delete key 13:
 Key 6 is in a leaf node, this is Case 2,
 Case 2.a delete k and find its predecessor and place it in key’s
position
24
Time complexity:(insert & delete)
 It takes O(h) for a B-Tree of height h in disk operation
 CPU time takes O(th)
= O (t 𝑙𝑜𝑔𝑡 n )
25
Usage of B-Tree
 Database: useful in searching
 File system: in NTFS directory to make finding an entry faster
26
Unindexed and unsorted data => O(n)
Key n
B-Tree => O(log n)
References
1 Cormen, T., Leiserson, C., Rivest, R. and Stein, C. (2014). Introduction to
algorithms. Cambridge, Massachusetts: The MIT Press.
2 Kaltenbrunner, A., Kellis, L. and Mart´, D. (n.d.). B-trees. [ebook] Available at:
http://www.di.ufpb.br/lucidio/Btrees.pdf [Accessed 25 Dec. 2017].
3 Koruga, P. and Bača, M. (n.d.). Analysis of B-tree data structure and its usage in
computer forensics. [ebook] p.4. Available at:
https://www.scribd.com/document/112071035/B-Tree-Application [Accessed 27
Dec. 2017].
27
Any Question!
Thank you 😘
28

More Related Content

What's hot

Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data StructureDharita Chokshi
 
Binary tree and operations
Binary tree and operations Binary tree and operations
Binary tree and operations varagilavanya
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structureAbrish06
 
Breadth first search and depth first search
Breadth first search and  depth first searchBreadth first search and  depth first search
Breadth first search and depth first searchHossain Md Shakhawat
 
Topological Sorting
Topological SortingTopological Sorting
Topological SortingShahDhruv21
 
Search tree,Tree and binary tree and heap tree
Search tree,Tree  and binary tree and heap treeSearch tree,Tree  and binary tree and heap tree
Search tree,Tree and binary tree and heap treezia eagle
 
Mapping cardinalities
Mapping cardinalitiesMapping cardinalities
Mapping cardinalitiesArafat Hossan
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structureMAHALAKSHMI P
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structureschauhankapil
 
trees in data structure
trees in data structure trees in data structure
trees in data structure shameen khan
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort AlgorithmLemia Algmri
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked listFahd Allebdi
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search TreeAbhishek L.R
 

What's hot (20)

B tree
B treeB tree
B tree
 
Linked List
Linked ListLinked List
Linked List
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
Data Structure (Tree)
Data Structure (Tree)Data Structure (Tree)
Data Structure (Tree)
 
Binary tree and operations
Binary tree and operations Binary tree and operations
Binary tree and operations
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Breadth first search and depth first search
Breadth first search and  depth first searchBreadth first search and  depth first search
Breadth first search and depth first search
 
Topological Sorting
Topological SortingTopological Sorting
Topological Sorting
 
Search tree,Tree and binary tree and heap tree
Search tree,Tree  and binary tree and heap treeSearch tree,Tree  and binary tree and heap tree
Search tree,Tree and binary tree and heap tree
 
Mapping cardinalities
Mapping cardinalitiesMapping cardinalities
Mapping cardinalities
 
Dbms 4NF & 5NF
Dbms 4NF & 5NFDbms 4NF & 5NF
Dbms 4NF & 5NF
 
Linked list
Linked listLinked list
Linked list
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
 
Double ended queue
Double ended queueDouble ended queue
Double ended queue
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structures
 
Ppt bubble sort
Ppt bubble sortPpt bubble sort
Ppt bubble sort
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 

Similar to B tree

Similar to B tree (20)

b-tree.ppt
b-tree.pptb-tree.ppt
b-tree.ppt
 
Lec16
Lec16Lec16
Lec16
 
Btreesprogramme
BtreesprogrammeBtreesprogramme
Btreesprogramme
 
BTree.pptx
BTree.pptxBTree.pptx
BTree.pptx
 
Lec16
Lec16Lec16
Lec16
 
(a) There are three ways to traverse a binary tree pre-order, in-or.docx
(a) There are three ways to traverse a binary tree pre-order, in-or.docx(a) There are three ways to traverse a binary tree pre-order, in-or.docx
(a) There are three ways to traverse a binary tree pre-order, in-or.docx
 
B trees
B treesB trees
B trees
 
B+ tree.pptx
B+ tree.pptxB+ tree.pptx
B+ tree.pptx
 
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
 
Presentation on b trees [autosaved]
Presentation on b trees [autosaved]Presentation on b trees [autosaved]
Presentation on b trees [autosaved]
 
08 B Trees
08 B Trees08 B Trees
08 B Trees
 
Trees
TreesTrees
Trees
 
B tree by-jash acharya
B tree by-jash acharyaB tree by-jash acharya
B tree by-jash acharya
 
part4-trees.ppt
part4-trees.pptpart4-trees.ppt
part4-trees.ppt
 
Btree
BtreeBtree
Btree
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
B TREE ( a to z concept ) in data structure or DBMS
B TREE ( a to z concept ) in data structure  or DBMSB TREE ( a to z concept ) in data structure  or DBMS
B TREE ( a to z concept ) in data structure or DBMS
 
Fileprocessing lec-7
Fileprocessing lec-7Fileprocessing lec-7
Fileprocessing lec-7
 
B trees
B treesB trees
B trees
 
B and B+ tree
B and B+ treeB and B+ tree
B and B+ tree
 

Recently uploaded

costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 

Recently uploaded (20)

costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 

B tree

  • 1. Presented By: Fatimah M. Alqadheeb 218002332
  • 2. Content  Introduction  B-Tree Properties  The Height of a B-Tree  Basic Operation in a B-Tree  Inserting  Deleting  Time Complexity  Usage of B-Tree  References 2
  • 3. Quote of the Day! 3
  • 4. Introduction:  In case of too large data that could not be fit in a main memory  So, that’s require to access the disk multiple of times  Accessing the disk requires long time  We need to reduce the number of disk access!  The solution is to use the B-Tree, which gives more branches with less height 4
  • 5. B-Tree  B-Tree: is a balanced rooted tree whose root is T root.  Properties of B- Tree: 1. For every node x in B- Tree: a. x.n the number of keys in x node b. The x.n keys themselves x. key1, x. key2, …, x. keyn (increasing order) c. x.leaf is a Boolean value that is true if x is a leaf & false if x is an internal node x.n x. 𝒌𝒆𝒚 𝟏 x. 𝒌𝒆𝒚 𝟐 x. 𝒌𝒆𝒚 𝟑 5
  • 6. 10 16 1 2 3 9 11 12 13 14 17 20 Cont. Properties of B- Tree: … 1. Each internal node x also contains x.n+1 pointers x. 𝒄 𝟏, x. 𝒄 𝟐, …, x. 𝒄 𝒙.𝒏+𝟏 2. The keys x. 𝒌𝒆𝒚𝐢 separates the ranges of keys in the subtree x. 𝒄𝐢 as 𝐤 𝐢 <= x. 𝒌𝒆𝒚𝐢 <= x. 𝒌𝒆𝒚𝐢+𝟏<= …<= x. 𝒌𝒆𝒚 𝒏 <=x. 𝒌𝒆𝒚 𝒏+𝟏 1 2 3 … x. 𝒄 𝟏 x. 𝒄 𝟐 x. 𝒄 𝟑 6
  • 7. 4. All the leaves have the same depth which is the tree’s height h o h <= 𝑙𝑜𝑔𝑡 𝑛+1 2 5. Nodes have upper and lower bounds of the keys they can contain, the minimum degree of the B- Tree is t >= 2 a. Every node other than the root must have at least t-1 keys o The internal node has at least t children b. Every node may contain the root at most 2t-1 keys o The internal node has at most 2t children Cont. Properties of B- Tree: 7
  • 8. Basic Operation in a B- Tree  Create  Search  Insert  Delete 8
  • 9. Insert a Key into a B- Tree when x is a leaf node when x has children decide which one to go ! when child is full => splitting 9
  • 10. Example 1: (Insertion into B- Tree)  Insert key = 2 ? 7 13 16 24 1 3 4 5 10 11 14 15 18 19 20 21 22 25 26 10
  • 11.  Insert key = 2? o i=x.n = 4 o if x.leaf? => false o else while(i >= 1 and 2 < x.𝑘𝑒𝑦𝑖) • i=4 >1 && 2<24 => i=4-1 = 3 • i=3>1 && 2<16 => i=3-1=2 • i=2 && 2<13 => i=2-1=1 • i=1 && 2<7 => i=1-1=0 o Out from while loop i=0+1=1 o DISK-READ (x. 𝑐1) o if x. 𝑐1 .n == 2t-1? x. 𝑐1 .n =4 = 5 it’s not full! o B-TREE-INSERT-NONFULL(x. 𝑐1 .n,2) x 11
  • 12.  Insert key = 2? o i=x.n = 4 o if x.leaf? => true o while(i >= 1 and 2 < x.𝑘𝑒𝑦𝑖) • i=4 >1 && 2<5 => x.𝑘𝑒𝑦4+1=5 , i=3 • i=3>1 && 2<4 => x.𝑘𝑒𝑦3+1=4 , i=2 • i=2 && 2<3 => x.𝑘𝑒𝑦2+1=3 , i=1 • i=1 && 2<1 => Out from while loop i=1 o x.𝑘𝑒𝑦1+1=2 , x.n = 5 o DISK-WRITE(x) x 12
  • 13. Example 1: (Insertion into B- Tree) 7 13 16 24 1 2 3 4 5 10 11 14 15 18 19 20 21 22 25 26 x.𝑘𝑒𝑦2  The B-Tree after inserting key =2 13
  • 14. Example 2: (Insertion into B- Tree) 7 13 16 24 1 2 3 4 5 10 11 14 15 18 19 20 21 22 25 26  Insert key = 17 ? 14
  • 15.  Insert key = 17? o i=x.n = 4 o if x.leaf? => false o else while(i >= 1 and 2 < x.𝑘𝑒𝑦𝑖) • i=4 >1 && 17<24 => i=4-1 = 3 • i=3>1 && 17<16 => Out from while loop i=3+1=4 • DISK-READ (x. 𝑐4) o if x. 𝑐1 .n == 2t-1? x. 𝑐1 .n = 5 = 5 it’s full! o B-TREE-SPLIT-CHILD(x. 𝑐4, 4) x 15
  • 16. Example 2: (Insertion into B- Tree) 7 13 16 24 1 3 4 5 10 11 14 15 18 19 20 21 22 25 26 20 10 11 10 11 16
  • 17. Example 2: (Insertion into B- Tree)  The new B-Tree after splitting 7 13 16 20 24 1 2 3 4 5 10 11 14 15 18 19 25 2621 22 17
  • 18.  Insert key = 17? o if k > x.𝑘𝑒𝑦4 ? => 17 > 22 o B-TREE-INSERT-NONFULL(x. 𝑐4 .n, 17) o … x.𝑘𝑒𝑦2  The B-Tree after inserting key = 17 18
  • 19. Deleting a key in a B-Tree 1. If the key k is in node x and x is a leaf, delete the key k from x. 2. If the key k is in node x and x is an internal node, do the following: a. If the child y that precedes k in node x has at least t keys, then find the predecessor of k in the subtree rooted at y. then delete k and replace k by its predecessor b. If y has fewer than t keys, then, look at the next z child that follows y child if z has at least t keys, then find the successor of k then delete the k and replace it with its successor. c. If both y and z have only t-1 keys, merge k with all keys in z to the child y, then delete the k from y 19
  • 20. Deleting a key in a B-Tree 3. If the key k is not present in internal node x, determine the root x.𝒄𝒊 of the appropriate subtree that must contain k. Note: necessary to guarantee that we descend to a node containing at least t keys, do the following: a. If x.𝒄𝒊 has only t -1 keys but has an immediate sibling with at least t keys, give x.𝑐𝑖 an extra key by moving a key from x down into x.𝑐𝑖, moving a key from x.𝑐𝑖’s immediate left or right sibling up into x. then delete the key b. If x.𝑐𝑖 and both of x.𝑐𝑖 ’s immediate siblings have t -1 keys, merge 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, then delete the key 20
  • 21. Example 1: Deleting a key in a B-Tree  Delete key 6:  Key 6 is in a leaf node, this is Case 1 , Just delete it 21 t=3
  • 22. Example 2: Deleting a key in a B-Tree  Delete key 13:  Key 6 is in a leaf node, this is Case 2, 22
  • 23. Example 2: Deleting a key in a B-Tree  Delete key 13:  Key 6 is in a leaf node, this is Case 2,  Case 2.a delete k and find its predecessor and place it in key’s position 23
  • 24. Example 2: Deleting a key in a B-Tree  Delete key 13:  Key 6 is in a leaf node, this is Case 2,  Case 2.a delete k and find its predecessor and place it in key’s position 24
  • 25. Time complexity:(insert & delete)  It takes O(h) for a B-Tree of height h in disk operation  CPU time takes O(th) = O (t 𝑙𝑜𝑔𝑡 n ) 25
  • 26. Usage of B-Tree  Database: useful in searching  File system: in NTFS directory to make finding an entry faster 26 Unindexed and unsorted data => O(n) Key n B-Tree => O(log n)
  • 27. References 1 Cormen, T., Leiserson, C., Rivest, R. and Stein, C. (2014). Introduction to algorithms. Cambridge, Massachusetts: The MIT Press. 2 Kaltenbrunner, A., Kellis, L. and Mart´, D. (n.d.). B-trees. [ebook] Available at: http://www.di.ufpb.br/lucidio/Btrees.pdf [Accessed 25 Dec. 2017]. 3 Koruga, P. and Bača, M. (n.d.). Analysis of B-tree data structure and its usage in computer forensics. [ebook] p.4. Available at: https://www.scribd.com/document/112071035/B-Tree-Application [Accessed 27 Dec. 2017]. 27