SlideShare a Scribd company logo
1 of 17
Sudan University for Science and Technology
          College of graduate studies
          Msc in Computer Science



               B-Trees
           Space & time tradeoffs

Presented by
Mohamed Zeinelabdeen Abdelgader
Outline

   Space & time tradeoffs
   B-tree

   Definition

   Search in B-Tree




                             2
Space & time tradeoffs
Two varieties of space & time algorithms:
 input enhancement — preprocess the input (or its part) to
    store some info to be used later in solving the problem
        string searching algorithms


   prestructuring — preprocess the input to make accessing its
    elements easier
        indexing schemes (e.g., B-trees)




                                                                  3
B-tree
   The B-tree's creators, R.Bayer and E.
    McCreight. The most common belief is
    that B stands for balanced, as all the leaf
    nodes are at the same level in the tree. B
    may also stand for Bayer, or for Boeing,
    because they were working for Boeing
    Scientific Research Labs at the time.



                                                  4
n[x]                       leaf[x]
                                    3       FALSE

Definition                              Q   T   X     keyi[x]
                                                      i=1..n[x]

 A B-tree T is a rooted tree having the following
   properties:
  1 Every node x has the following fields
      n[x], the number of keys currently stored in node x
      The n[x] keys themselves stored in nondecreasing
       order, so that key1[x] ≤ key2[x] ≤ … ≤ keyn[x] [x]
      Leaf[x],a boolean value that is TRUE if x is a leaf and
       FALSE if x is an internal node.


                                                                5
n[x]                       leaf[x]
                                   3       FALSE

(cont.)              ci[x]
                                       Q   T   X    keyi[x]
                                   ... … … …        i=1..n[x]
                     i=1..n[x]+1

 2 Each internal node x also contains n[x]+1
  pointers c1[x], c2[x],…,cn[x]+1[x] to its children.
  leaf nodes have no children, so their ci fields are
  undefined
 3 The keys keyi[x] separate the ranges of keys
  stored in each subtree:if ki is any key stored in
  the subtree with root ci[x], then
k1≤ key1 [x] ≤ k2 ≤ key2 [x] ≤… ≤ keyn[x] [x] ≤
  kn[x]+1
                                                              6
n[x]                       leaf[x]
                                3       FALSE

(cont.)           ci[x]
                                    Q   T   X    keyi[x]
                                ... … … …        i=1..n[x]
                  i=1..n[x]+1

   4 All leaves have the same depth, which is
    the tree’s height h.
   5 There are lower and upper bounds on
    the number of keys a node can
    contain.These bounds can be expressed in
    terms of a fixed integer t≥2 called a
    minimum degree of the B-tree:

                                                           7
n[x]                       leaf[x]
                                   3       FALSE

(cont.)              ci[x]
                                       Q   T   X    keyi[x]
                                   ... … … …        i=1..n[x]
                     i=1..n[x]+1

    Every node other than the root must have
     at least t-1 keys. Every internal node other
     than the root thus has at least t children, If
     the tree is nonempty, the root must have
     at least one key
    Every node other than the root can contain
     at most 2t-1 keys, therefore, an internal
     node can have at most 2t children. we say
     that a node is full if it contains exactly 2t-1
     keys
                                                              8
Search-overview
      The search operation on a B-tree is
       analogous to a search on a binary tree.
      Instead of choosing between a left and a
       right child as in a binary tree, a B-tree search
       must make an (n[x] +1)-way choice. The
       correct child is chosen by performing a linear
       search of the values in the node.




                                                     9
Search-example




Search for key R

                   10
Search analysis

    After finding the value greater than or equal
     to the desired value, the child pointer to the
     immediate left of that value is followed. If all
     values are less than the desired value, the
     rightmost child pointer is followed.
    Of course, the search can be terminated as
     soon as the desired node is found.




                                                        11
Thm: Let T be a B-tree with n>2 keys and t ≥ 2 of minimum degree
. Then the height h of the
B-tree is bounded above by
Algorithm

  B-TREE-SEARCH(x,k)
   i←1
   while i ≤ n[x] and k > keyi[x]
       do i ← i + 1
   if i ≤ n[x] and k = keyi[x]
       then return (x, i)
   if leaf[x]
       then return NIL
        else Disk-Read(ci[x])
            return B-Tree-Search(ci[x], k)
                                             13
Algorithm analysis
   Input size=Number of children of node.
   Basic operation=
         Disk-Read(ci[x])
   Cases:
       Best case : When find the key in the current node.
            T(n) Є θ(1).
       Average case : When the key is not find in the
        current node.


                                                             14
Algorithm analysis

     The recurrence relation:
          T(n)=T(n/t)+θ(1) where t>= 2

     To solve the recurrence Use the master
      Theorem:
            T(n)=aT(n/b)+f(n) where f(n) Є θ (nd) , a>=1 b>=2 d>=0
                        If a<bd , T(n) Є θ( (nd)
                        If a = bd , T(n) Є θ (nd log n)
                        If a>bd    , T(n) Є θ(nlogab)
      a=1 , b=t , d=0

                        T(n) Є   θ(logn)                             15
References
Introduction to The Design and Analysis
 Algorithms
B trees

More Related Content

What's hot

Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search TreeZafar Ayub
 
Binary Search Tree and AVL
Binary Search Tree and AVLBinary Search Tree and AVL
Binary Search Tree and AVLKatang Isip
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)Trupti Agrawal
 
Lecture 11 data structures and algorithms
Lecture 11 data structures and algorithmsLecture 11 data structures and algorithms
Lecture 11 data structures and algorithmsAakash deep Singhal
 
Hyper loglog
Hyper loglogHyper loglog
Hyper loglognybon
 
Mat221 5.6 definite integral substitutions and the area between two curves
Mat221 5.6 definite integral substitutions and the area between two curvesMat221 5.6 definite integral substitutions and the area between two curves
Mat221 5.6 definite integral substitutions and the area between two curvesGlenSchlee
 
Chapter 1 functions
Chapter 1  functionsChapter 1  functions
Chapter 1 functionsUmair Pearl
 
An Introduction to ECDSA and it's use in Bitcoin (1)
An Introduction to ECDSA and it's use in Bitcoin (1)An Introduction to ECDSA and it's use in Bitcoin (1)
An Introduction to ECDSA and it's use in Bitcoin (1)Hakeem Hunte
 
Tree and binary tree
Tree and binary treeTree and binary tree
Tree and binary treeZaid Shabbir
 
11 applications of factoring
11 applications of factoring11 applications of factoring
11 applications of factoringelem-alg-sample
 

What's hot (18)

Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Lec8
Lec8Lec8
Lec8
 
Binary Search Tree and AVL
Binary Search Tree and AVLBinary Search Tree and AVL
Binary Search Tree and AVL
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
 
gfg
gfggfg
gfg
 
Math 5 problem set
Math 5 problem setMath 5 problem set
Math 5 problem set
 
Lecture 11 data structures and algorithms
Lecture 11 data structures and algorithmsLecture 11 data structures and algorithms
Lecture 11 data structures and algorithms
 
recursion2
recursion2recursion2
recursion2
 
L3 some other properties
L3 some other propertiesL3 some other properties
L3 some other properties
 
Hyper loglog
Hyper loglogHyper loglog
Hyper loglog
 
L7 fuzzy relations
L7 fuzzy relationsL7 fuzzy relations
L7 fuzzy relations
 
Division Of Polynomials
Division Of PolynomialsDivision Of Polynomials
Division Of Polynomials
 
Mat221 5.6 definite integral substitutions and the area between two curves
Mat221 5.6 definite integral substitutions and the area between two curvesMat221 5.6 definite integral substitutions and the area between two curves
Mat221 5.6 definite integral substitutions and the area between two curves
 
Tree traversal techniques
Tree traversal techniquesTree traversal techniques
Tree traversal techniques
 
Chapter 1 functions
Chapter 1  functionsChapter 1  functions
Chapter 1 functions
 
An Introduction to ECDSA and it's use in Bitcoin (1)
An Introduction to ECDSA and it's use in Bitcoin (1)An Introduction to ECDSA and it's use in Bitcoin (1)
An Introduction to ECDSA and it's use in Bitcoin (1)
 
Tree and binary tree
Tree and binary treeTree and binary tree
Tree and binary tree
 
11 applications of factoring
11 applications of factoring11 applications of factoring
11 applications of factoring
 

Viewers also liked (7)

B tree short
B tree shortB tree short
B tree short
 
Multi ways trees
Multi ways treesMulti ways trees
Multi ways trees
 
B Trees
B TreesB Trees
B Trees
 
B-tree & R-tree
B-tree & R-treeB-tree & R-tree
B-tree & R-tree
 
Best for b trees
Best for b treesBest for b trees
Best for b trees
 
B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data Structure
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
 

Similar to B trees (20)

Btreesprogramme
BtreesprogrammeBtreesprogramme
Btreesprogramme
 
lecture 13
lecture 13lecture 13
lecture 13
 
15-btrees.ppt
15-btrees.ppt15-btrees.ppt
15-btrees.ppt
 
b-tree.ppt
b-tree.pptb-tree.ppt
b-tree.ppt
 
BTree.pptx
BTree.pptxBTree.pptx
BTree.pptx
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
B tree
B  treeB  tree
B tree
 
part4-trees.ppt
part4-trees.pptpart4-trees.ppt
part4-trees.ppt
 
Red Black Trees
Red Black TreesRed Black Trees
Red Black Trees
 
UNIT II.ppt
UNIT II.pptUNIT II.ppt
UNIT II.ppt
 
Trees
TreesTrees
Trees
 
7.tree
7.tree7.tree
7.tree
 
trees.ppt
trees.ppttrees.ppt
trees.ppt
 
Unit 3
Unit 3Unit 3
Unit 3
 
Unit 3
Unit 3Unit 3
Unit 3
 
Dynamic multi level indexing Using B-Trees And B+ Trees
Dynamic multi level indexing Using B-Trees And B+ TreesDynamic multi level indexing Using B-Trees And B+ Trees
Dynamic multi level indexing Using B-Trees And B+ Trees
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
Chap 5 Tree.ppt
Chap 5 Tree.pptChap 5 Tree.ppt
Chap 5 Tree.ppt
 
Skiena algorithm 2007 lecture05 dictionary data structure trees
Skiena algorithm 2007 lecture05 dictionary data structure treesSkiena algorithm 2007 lecture05 dictionary data structure trees
Skiena algorithm 2007 lecture05 dictionary data structure trees
 
Binary trees1
Binary trees1Binary trees1
Binary trees1
 

More from Mohamed Zeinelabdeen Abdelgader Farh jber

الآثار الأخلاقية المترتبة على الملكية الفكرية في أفريقيا
الآثار الأخلاقية المترتبة على الملكية الفكرية في أفريقياالآثار الأخلاقية المترتبة على الملكية الفكرية في أفريقيا
الآثار الأخلاقية المترتبة على الملكية الفكرية في أفريقياMohamed Zeinelabdeen Abdelgader Farh jber
 
Comparison of the workflow management systems bizagi, process maker, and joget
Comparison of the workflow management systems bizagi, process maker, and jogetComparison of the workflow management systems bizagi, process maker, and joget
Comparison of the workflow management systems bizagi, process maker, and jogetMohamed Zeinelabdeen Abdelgader Farh jber
 
Comparison of the workflow management systems bizagi, process maker, and joget
Comparison of the workflow management systems bizagi, process maker, and jogetComparison of the workflow management systems bizagi, process maker, and joget
Comparison of the workflow management systems bizagi, process maker, and jogetMohamed Zeinelabdeen Abdelgader Farh jber
 

More from Mohamed Zeinelabdeen Abdelgader Farh jber (13)

الآثار الأخلاقية المترتبة على الملكية الفكرية في أفريقيا
الآثار الأخلاقية المترتبة على الملكية الفكرية في أفريقياالآثار الأخلاقية المترتبة على الملكية الفكرية في أفريقيا
الآثار الأخلاقية المترتبة على الملكية الفكرية في أفريقيا
 
موزع البريد الرقمي
موزع البريد الرقمي موزع البريد الرقمي
موزع البريد الرقمي
 
Comparison of the workflow management systems bizagi, process maker, and joget
Comparison of the workflow management systems bizagi, process maker, and jogetComparison of the workflow management systems bizagi, process maker, and joget
Comparison of the workflow management systems bizagi, process maker, and joget
 
Comparison of the workflow management systems bizagi, process maker, and joget
Comparison of the workflow management systems bizagi, process maker, and jogetComparison of the workflow management systems bizagi, process maker, and joget
Comparison of the workflow management systems bizagi, process maker, and joget
 
Black & White Box testing
Black & White Box testingBlack & White Box testing
Black & White Box testing
 
Workflow Management Systems Comparison Study
 Workflow Management Systems Comparison Study Workflow Management Systems Comparison Study
Workflow Management Systems Comparison Study
 
Transaction management transparencies
Transaction management transparenciesTransaction management transparencies
Transaction management transparencies
 
Transaction management for a main memory database
Transaction management for a main memory databaseTransaction management for a main memory database
Transaction management for a main memory database
 
Embedded systems1
Embedded systems1Embedded systems1
Embedded systems1
 
Web servers
Web serversWeb servers
Web servers
 
Requirements engineering
Requirements engineeringRequirements engineering
Requirements engineering
 
Online Msc Application Workflow Management System
Online Msc Application Workflow Management SystemOnline Msc Application Workflow Management System
Online Msc Application Workflow Management System
 
DISTRIBUTED DATABASE
DISTRIBUTED DATABASEDISTRIBUTED DATABASE
DISTRIBUTED DATABASE
 

Recently uploaded

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
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
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
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
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
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
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
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
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
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
 

Recently uploaded (20)

Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
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
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
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
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
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
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
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
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
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
 

B trees

  • 1. Sudan University for Science and Technology College of graduate studies Msc in Computer Science B-Trees Space & time tradeoffs Presented by Mohamed Zeinelabdeen Abdelgader
  • 2. Outline  Space & time tradeoffs  B-tree  Definition  Search in B-Tree 2
  • 3. Space & time tradeoffs Two varieties of space & time algorithms:  input enhancement — preprocess the input (or its part) to store some info to be used later in solving the problem  string searching algorithms  prestructuring — preprocess the input to make accessing its elements easier  indexing schemes (e.g., B-trees) 3
  • 4. B-tree  The B-tree's creators, R.Bayer and E. McCreight. The most common belief is that B stands for balanced, as all the leaf nodes are at the same level in the tree. B may also stand for Bayer, or for Boeing, because they were working for Boeing Scientific Research Labs at the time. 4
  • 5. n[x] leaf[x] 3 FALSE Definition Q T X keyi[x] i=1..n[x] A B-tree T is a rooted tree having the following properties:  1 Every node x has the following fields  n[x], the number of keys currently stored in node x  The n[x] keys themselves stored in nondecreasing order, so that key1[x] ≤ key2[x] ≤ … ≤ keyn[x] [x]  Leaf[x],a boolean value that is TRUE if x is a leaf and FALSE if x is an internal node. 5
  • 6. n[x] leaf[x] 3 FALSE (cont.) ci[x] Q T X keyi[x] ... … … … i=1..n[x] i=1..n[x]+1  2 Each internal node x also contains n[x]+1 pointers c1[x], c2[x],…,cn[x]+1[x] to its children. leaf nodes have no children, so their ci fields are undefined  3 The keys keyi[x] separate the ranges of keys stored in each subtree:if ki is any key stored in the subtree with root ci[x], then k1≤ key1 [x] ≤ k2 ≤ key2 [x] ≤… ≤ keyn[x] [x] ≤ kn[x]+1 6
  • 7. n[x] leaf[x] 3 FALSE (cont.) ci[x] Q T X keyi[x] ... … … … i=1..n[x] i=1..n[x]+1  4 All leaves have the same depth, which is the tree’s height h.  5 There are lower and upper bounds on the number of keys a node can contain.These bounds can be expressed in terms of a fixed integer t≥2 called a minimum degree of the B-tree: 7
  • 8. n[x] leaf[x] 3 FALSE (cont.) ci[x] Q T X keyi[x] ... … … … i=1..n[x] i=1..n[x]+1  Every node other than the root must have at least t-1 keys. Every internal node other than the root thus has at least t children, If the tree is nonempty, the root must have at least one key  Every node other than the root can contain at most 2t-1 keys, therefore, an internal node can have at most 2t children. we say that a node is full if it contains exactly 2t-1 keys 8
  • 9. Search-overview  The search operation on a B-tree is analogous to a search on a binary tree.  Instead of choosing between a left and a right child as in a binary tree, a B-tree search must make an (n[x] +1)-way choice. The correct child is chosen by performing a linear search of the values in the node. 9
  • 11. Search analysis  After finding the value greater than or equal to the desired value, the child pointer to the immediate left of that value is followed. If all values are less than the desired value, the rightmost child pointer is followed.  Of course, the search can be terminated as soon as the desired node is found. 11
  • 12. Thm: Let T be a B-tree with n>2 keys and t ≥ 2 of minimum degree . Then the height h of the B-tree is bounded above by
  • 13. Algorithm B-TREE-SEARCH(x,k) i←1 while i ≤ n[x] and k > keyi[x] do i ← i + 1 if i ≤ n[x] and k = keyi[x] then return (x, i) if leaf[x] then return NIL else Disk-Read(ci[x]) return B-Tree-Search(ci[x], k) 13
  • 14. Algorithm analysis  Input size=Number of children of node.  Basic operation= Disk-Read(ci[x])  Cases:  Best case : When find the key in the current node.  T(n) Є θ(1).  Average case : When the key is not find in the current node. 14
  • 15. Algorithm analysis  The recurrence relation:  T(n)=T(n/t)+θ(1) where t>= 2  To solve the recurrence Use the master Theorem: T(n)=aT(n/b)+f(n) where f(n) Є θ (nd) , a>=1 b>=2 d>=0 If a<bd , T(n) Є θ( (nd) If a = bd , T(n) Є θ (nd log n) If a>bd , T(n) Є θ(nlogab) a=1 , b=t , d=0 T(n) Є θ(logn) 15
  • 16. References Introduction to The Design and Analysis Algorithms