SlideShare une entreprise Scribd logo
1  sur  46
Balanced Trees   (B and B+)
Completely Balanced Trees ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
B-Trees ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
B-Trees ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
B-Tree Definition ,[object Object],[object Object],[object Object],[object Object]
Multi-way Search Tree of order of 4 Keys Pointers
B-Trees
B-Tree Properties ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
B-Tree Properties 4.  Each leaf node (other than the root node if it is a leaf)    must contain at least   (m / 2)    - 1 keys.  Note:  x   is the ceiling function whose value is the smallest integer that  is greater than or equal to x. E.g.,     3    = 3    3.34   = 4    1.98    = 2    5.001    = 6
B-Tree Properties A B-tree is a fairly well-balanced tree since all leaf nodes must be at  the bottom.  Recall condition 2. All internal nodes (except perhaps the root node) have at least     (m / 2)    (nonempty) children    keep it bushy and balanced. Causes the tree to  fan out , i.e., shorter height
B-Tree Insertion ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Insertion Example Insert the following letters into what is originally an empty B-tree of order 5:  C N G A H E K Q M F W L T Z D P R X Y S  Order 5    max of 5 children and 4 keys. All nodes (except root) must have a minimum of 2 keys. Inserting in alphabetical order the first 4  letters:
Insertion Example Insert H next.  No room.  Split into 2 nodes.  Move median item G up into new root node Insert EKQ next
Insertion Example C N G A H   E K Q M  F W L T Z D P R X Y S Inserting E, K, & Q doesn’t require splits. But inserting M does ??  - split into 2
Insertion Example C N G A H E K Q M   F W L T  Z D P R X Y S F, W, L, and T are then added without needing any split.
Insertion Example C N G A H E K Q M   F W L T Z  D P R X Y S F, W, L, and T are then added without needing any split.   Adding Z requires node to split Move median (T) up & split node
Insertion Example Z
C N G A H E K Q M F W L T Z  D P R X Y S D (which is the median too) Insert PRXY without any splitting
C N G A H E K Q M F W L T Z   D P R X Y  S ,[object Object],[object Object],[object Object]
B Tree Deletion ,[object Object],[object Object],[object Object]
B Tree Deletion ,[object Object]
B Tree Deletion ,[object Object],[object Object]
B Tree Deletion ,[object Object],[object Object],[object Object],[object Object],α β γ
B Tree Deletion
B Tree Deletion - Delete E next - Very problematic    siblings as well as E has no extra keys - Combine the leaf with one of two siblings - Move down parent’s key that was between these two siblings
B Tree (Delete E)
B Tree Deletion ,[object Object],[object Object],[object Object]
B Tree Deletion
B+ Trees
B+-Tree ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
B+-Trees ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
B+-Tree Example ,[object Object],[object Object]
B+-Tree Insertions ,[object Object],[object Object]
The insert algorithm for B+ Trees Leaf Page Full Index Page FULL Action No No Place the record in sorted position in the appropriate leaf page Yes No ,[object Object],[object Object],[object Object],[object Object]
The insert algorithm for B+ Trees Leaf Page Full Index Page FULL Action Yes Yes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Insertion Example Adding record with Key 28:
Insertion Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Insert (Leaf full; index not) 70
Insert (Leaf and index pages are full) Add 95    belongs here Split leaf page into 2:  75  80  and  85  90  95 Middle key (85) goes up    parent is full    split parent 25  50  60    75  85 Middle key (60) made a new parent of the parents
Insert (Leaf and index pages are full) 95
Rotation When a leaf node is full and its sibling is not. Reduce number of page splits. E.g., add 70    previously, we split the  50  55  60  65 node and brought 60 up Instead, move a record to its sibling:
The delete algorithm for B+ Trees Leaf Page Below Fill Factor Index Page Below Fill Factor Action No  No Delete the record from the leaf page. Arrange keys in ascending order to fill void. If the key of the deleted record appears in the index page, use the next key to replace it. Yes No Combine the leaf page and its sibling. Change the index page to reflect the change.  Yes Yes ,[object Object],[object Object],[object Object]
Deletion Example Delete 70:  OK since fill factor = 50% (min# records in a node)
Deletion Example Now delete 25:  Leaf: OK (fill factor satisfied) Index: not OK    replace with 28
Deletion Example Delete 60:  fill factor < 50%    combine leaf pages and index pages
Deletion Example

Contenu connexe

Tendances

Trees - Data structures in C/Java
Trees - Data structures in C/JavaTrees - Data structures in C/Java
Trees - Data structures in C/Java
geeksrik
 

Tendances (20)

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
 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
 
Heap tree
Heap treeHeap tree
Heap tree
 
Binary search trees
Binary search treesBinary search trees
Binary search trees
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
 
b+ tree
b+ treeb+ tree
b+ tree
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
 
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
 
Red black tree
Red black treeRed black tree
Red black tree
 
Linked list
Linked listLinked list
Linked list
 
B and B+ tree
B and B+ treeB and B+ tree
B and B+ tree
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
Trees - Data structures in C/Java
Trees - Data structures in C/JavaTrees - Data structures in C/Java
Trees - Data structures in C/Java
 
B+ tree intro,uses,insertion and deletion
B+ tree intro,uses,insertion and deletionB+ tree intro,uses,insertion and deletion
B+ tree intro,uses,insertion and deletion
 
Tree Traversal
Tree TraversalTree Traversal
Tree Traversal
 
Balanced Tree (AVL Tree & Red-Black Tree)
Balanced Tree (AVL Tree & Red-Black Tree)Balanced Tree (AVL Tree & Red-Black Tree)
Balanced Tree (AVL Tree & Red-Black Tree)
 
Hash table
Hash tableHash table
Hash table
 
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search tree
 
Data structure - Graph
Data structure - GraphData structure - Graph
Data structure - Graph
 
Binary trees1
Binary trees1Binary trees1
Binary trees1
 

Similaire à Best for b trees

109885098-B-Trees-And-B-Trees in data structure.ppt
109885098-B-Trees-And-B-Trees in data structure.ppt109885098-B-Trees-And-B-Trees in data structure.ppt
109885098-B-Trees-And-B-Trees in data structure.ppt
ssuser19bb13
 
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmmIndexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
RAtna29
 
B-and-B-Tree-ppt presentation in data structure
B-and-B-Tree-ppt presentation in data structureB-and-B-Tree-ppt presentation in data structure
B-and-B-Tree-ppt presentation in data structure
ssuser19bb13
 
presentation on b tress. heap trees.hashing
presentation on b tress. heap trees.hashingpresentation on b tress. heap trees.hashing
presentation on b tress. heap trees.hashing
Bindiya syed
 

Similaire à Best for b trees (20)

109885098-B-Trees-And-B-Trees in data structure.ppt
109885098-B-Trees-And-B-Trees in data structure.ppt109885098-B-Trees-And-B-Trees in data structure.ppt
109885098-B-Trees-And-B-Trees in data structure.ppt
 
Trees
TreesTrees
Trees
 
B tree
B treeB tree
B tree
 
B trees dbms
B trees dbmsB trees dbms
B trees dbms
 
Btree
BtreeBtree
Btree
 
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
 
Unit 3.ppt
Unit 3.pptUnit 3.ppt
Unit 3.ppt
 
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmmIndexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
 
Indexing.ppt
Indexing.pptIndexing.ppt
Indexing.ppt
 
B+ trees and height balance tree
B+ trees and height balance treeB+ trees and height balance tree
B+ trees and height balance tree
 
B-and-B-Tree-ppt presentation in data structure
B-and-B-Tree-ppt presentation in data structureB-and-B-Tree-ppt presentation in data structure
B-and-B-Tree-ppt presentation in data structure
 
presentation on b tress. heap trees.hashing
presentation on b tress. heap trees.hashingpresentation on b tress. heap trees.hashing
presentation on b tress. heap trees.hashing
 
Lecture notes data structures tree
Lecture notes data structures   treeLecture notes data structures   tree
Lecture notes data structures tree
 
trees
trees trees
trees
 
B+tree
B+treeB+tree
B+tree
 
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
 
B trees and_b__trees
B trees and_b__treesB trees and_b__trees
B trees and_b__trees
 
Balance tree. Short overview
Balance tree. Short overviewBalance tree. Short overview
Balance tree. Short overview
 
Data structure tree - intermediate
Data structure tree - intermediateData structure tree - intermediate
Data structure tree - intermediate
 
08 B Trees
08 B Trees08 B Trees
08 B Trees
 

Dernier

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Dernier (20)

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 

Best for b trees

  • 1. Balanced Trees (B and B+)
  • 2.
  • 3.
  • 4.
  • 5.
  • 6. Multi-way Search Tree of order of 4 Keys Pointers
  • 8.
  • 9. B-Tree Properties 4. Each leaf node (other than the root node if it is a leaf) must contain at least  (m / 2)  - 1 keys. Note:  x  is the ceiling function whose value is the smallest integer that is greater than or equal to x. E.g.,  3  = 3  3.34  = 4  1.98  = 2  5.001  = 6
  • 10. B-Tree Properties A B-tree is a fairly well-balanced tree since all leaf nodes must be at the bottom. Recall condition 2. All internal nodes (except perhaps the root node) have at least  (m / 2)  (nonempty) children  keep it bushy and balanced. Causes the tree to fan out , i.e., shorter height
  • 11.
  • 12. Insertion Example Insert the following letters into what is originally an empty B-tree of order 5: C N G A H E K Q M F W L T Z D P R X Y S Order 5  max of 5 children and 4 keys. All nodes (except root) must have a minimum of 2 keys. Inserting in alphabetical order the first 4 letters:
  • 13. Insertion Example Insert H next. No room. Split into 2 nodes. Move median item G up into new root node Insert EKQ next
  • 14. Insertion Example C N G A H E K Q M F W L T Z D P R X Y S Inserting E, K, & Q doesn’t require splits. But inserting M does ?? - split into 2
  • 15. Insertion Example C N G A H E K Q M F W L T Z D P R X Y S F, W, L, and T are then added without needing any split.
  • 16. Insertion Example C N G A H E K Q M F W L T Z D P R X Y S F, W, L, and T are then added without needing any split. Adding Z requires node to split Move median (T) up & split node
  • 18. C N G A H E K Q M F W L T Z D P R X Y S D (which is the median too) Insert PRXY without any splitting
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 25. B Tree Deletion - Delete E next - Very problematic  siblings as well as E has no extra keys - Combine the leaf with one of two siblings - Move down parent’s key that was between these two siblings
  • 27.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36. Insertion Example Adding record with Key 28:
  • 37.
  • 38. Insert (Leaf full; index not) 70
  • 39. Insert (Leaf and index pages are full) Add 95  belongs here Split leaf page into 2: 75 80 and 85 90 95 Middle key (85) goes up  parent is full  split parent 25 50 60 75 85 Middle key (60) made a new parent of the parents
  • 40. Insert (Leaf and index pages are full) 95
  • 41. Rotation When a leaf node is full and its sibling is not. Reduce number of page splits. E.g., add 70  previously, we split the 50 55 60 65 node and brought 60 up Instead, move a record to its sibling:
  • 42.
  • 43. Deletion Example Delete 70: OK since fill factor = 50% (min# records in a node)
  • 44. Deletion Example Now delete 25: Leaf: OK (fill factor satisfied) Index: not OK  replace with 28
  • 45. Deletion Example Delete 60: fill factor < 50%  combine leaf pages and index pages