SlideShare a Scribd company logo
B AND B+ TREE
Details Of B Tree
Definition:-
 B-Tree is a generalization of a binary search tree designed especially for use on disk.
 So, B-trees used to represent very large dictionaries that reside on disk.
 This is the special case of M-Way tree.
 B-Tree Consists of Root Node, Branch Node and Leaf Node containing indexed field value in
ending nodes of the tree.
 B-trees are a good example of a data structure for external memory.
 It is commonly used in databases and filesystems.
 In order to maintain the pre-defined range, internal nodes may be joined or split.
 Each internal node of a B-tree contains a number of keys.
 The keys act as separation values which divide its subtrees.
 B-trees may waste some space (memory)
* Since nodes are not entirely full.
 If the B-tree is balanced, its search / insert / add operations take about log(n) steps.
Properties of B Tree:-
B-Tree of order n
 Not empty => root has at least 2 children.
 Remaining internal nodes (if any) have at least ceil (m/2) children.
 All leaves are at the same depth in the tree.
 Non-leaf node with k children has k-1 keys.
 It may contain large number of keys.
Operation on B+ Tree:-
 Searching.
 Insertion.
 Deletion.
Searching:-
 In B-Tree search start from Root node but every time we make 2-way decision.
Steps for searching :-
 Let the key to be searched be k.
 Search is similar to search in Binary Search Tree.
1. We start from root and recursively traverse down.
2. For every visited non-leaf node, if the node has key, we simply return the node.
3. Otherwise we recur down to the appropriate child (The child which is just before
the first greater key) of the node.
4. If we reach a leaf node and don’t find k in the leaf node, we return NULL.
Insertion:-
 Steps for insertion :-
Let the key to be inserted be k.
1. A new key is always inserted at leaf node.
2. Like BST, we start from root and traverse down till we reach a leaf node.
3. Once we reach a leaf node, we insert the key in that leaf node. Unlike BSTs, we have a predefined
range on number of keys that a node can contain.
4. So before inserting a key to node, we make sure that the node has extra space.
5. To insert a new key, we go down from root to leaf.
6. Before traversing down to a node, we first check if the node is full.
7. If the node is full, we split it to create space.
Insertion Example :-
 key :- 1,12,8,2,25,6,14,28,17,7,52,16,48,68.
Order = 5
Procedure for adding key in b-tree
Step1.
Step2.
Step3.
Step4.
Step5.
Deletion:-
1. Deletion from a B-tree is more complicated than insertion, because we can delete a key from
any node-not just a leaf.
2. when we delete a key from an internal node, we will have to rearrange the
node’s children.
3. Just as we had to ensure that a node didn’t get too big due to insertion
4. we must ensure that a node doesn’t get too small during deletion.
5. a simple approach to deletion might have to back up if a node (other than the root) along the
path to where the key is to be deleted has the minimum number of keys.
6. Since most of the keys in a B-tree are in the leaves, deletion operations are most often used to
delete keys from leaves.
7. The recursive delete procedure then acts in one downward pass through the tree, without
having to back up.
8. When deleting a key in an internal node, however, the procedure makes a downward pass
through the tree but may have to return to the node from which the key was deleted to replace
the key with its predecessor or successor.
9. No of children must be according to the ceil of m/2.
Deletion Example:-
 Given Tree:-
6 deleted
13 deleted
7 deleted
Analysis Of B Tree
 For a B-Tree of order M
1. Each internal node has up to M-1 keys to search
2. Each internal node has between M/2 and M children
3. Depth of B-Tree storing N items is O(log M/2 N)
 Find: Run time is:
1. O(log M) to binary search which branch to take at each node. But M is small
compared to N.
2. Total time to find an item is O(depth*log M) = O(log N)
Details Of B+ Tree
Definition:-
 The most commonly implemented form of the B-Tree is the B+-Tree.
 The order of the B+ tree determines the number of subtrees, which exactly
follows the B-Tree definition.
 A B+ tree is a data structure often used in the implementation of database
indexes.
 Only Leaf nodes store references to data.
 A leaf node may store more or less data records than an internal node stores
keys.
 It contains index pages and data pages.
 The data pages always appear as leaf nodes in the tree.
 The root node and intermediate nodes are always index pages.
Properties of B+ Tree:-
For a B-tree of order m:
 All data are on the same level.
 If a B+ tree consists of a single node, then the node is both a root and a leaf.
 Each internal node other than the root contains between m/2 search keys.
 The capacity of a leaf has to be 50% or more.
Operation on B+ Tree:-
 Searching.
 Insertion.
 Deletion.
Searching:-
1. Searching just like in a binary search tree.
2. Starts at the root, works down to the leaf level.
3. Does a comparison of the search value and the current “separation value”,
goes left or right.
4. Since no structure change in a B+ tree during a searching process.
5. So just compare the key value with the data in the tree, then give the result
back.
Insertion:-
1. A search is first performed, using the value to be added.
2. After the search is completed, the location for the new value is known.
3. If the tree is empty, add to the root.
4. Once the root is full, split the data into 2 leaves, using the root to hold keys
and pointers.
5. If adding an element will overload a leaf, take the median and split it.
Insertion Example :-
 Example #1: insert 28 into the below tree.
Result:-
 Example #2: insert 70 into below tree
Result:-
 Example #3: insert 95 into below tree
Result:-
Deletion:-
1. Deletion, like insertion, begins with a search.
2. When the item to be deleted is located and removed, the tree must be
checked to make sure no rules are violated.
3. The rule to focus on is to ensure that each node has at least ceil (n/2)
pointers.
Deletion Example :-
 Example #1: delete 70 from the tree
Result:-
 Example #2: delete 25 from below tree
Result:-
Replace 25 with 28 in the index page.
On Next Slide…
B and B+ tree
 Example #3: delete 60 from the below tree
Result:-
Analysis Of B+ Tree
 For a B+-Tree Searching Operation:-
1. During the search operation, h nodes are read from the disk to the main
memory where h is the height of the B+-tree.
2. So, the height of the B+-tree is h = O(logn), and the time complexity
of each linear search is O(t), Thus, the total time complexity of the
B+-tree search operation is O(t logt n).
 For a B+-Tree Insertion Operation:-
1. The time complexity of the insertion algorithm is O(t · logtn).
2. where the cofficient t is due to the operations performed for each node in
the main memory.
Analysis Of B+ Tree
 For a B+-Tree Deletion Operation:-
1. The time complexity of the insertion algorithm is O(t · logtn).
2. Each time we encounter a node having exactly t children (non-leaf node)
or keys (leaf node)
B and B+ tree

More Related Content

PPTX
Binary Search Tree
PPT
b+ tree
PPT
B trees in Data Structure
PDF
Trees, Binary Search Tree, AVL Tree in Data Structures
PPTX
trees in data structure
PPTX
Tree Traversal
PPTX
Data structures trees - B Tree & B+Tree.pptx
PPTX
Binary Search Tree in Data Structure
Binary Search Tree
b+ tree
B trees in Data Structure
Trees, Binary Search Tree, AVL Tree in Data Structures
trees in data structure
Tree Traversal
Data structures trees - B Tree & B+Tree.pptx
Binary Search Tree in Data Structure

What's hot (20)

PPTX
Data structure - Graph
PPTX
Doubly Linked List
PPTX
Breadth First Search & Depth First Search
PPTX
Tree - Data Structure
PPTX
Linked list
PPTX
Priority Queue in Data Structure
PPT
1.1 binary tree
PPTX
Linked List - Insertion & Deletion
PPTX
Red black tree in data structure
PDF
sparse matrix in data structure
PPT
16. Concurrency Control in DBMS
PPTX
Linked list
DOC
Time and space complexity
PPT
Binary Search
PPTX
Binary Tree in Data Structure
PPSX
Data Structure (Tree)
PDF
Array data structure
PPT
Binary search tree(bst)
PPTX
Data Structures : hashing (1)
Data structure - Graph
Doubly Linked List
Breadth First Search & Depth First Search
Tree - Data Structure
Linked list
Priority Queue in Data Structure
1.1 binary tree
Linked List - Insertion & Deletion
Red black tree in data structure
sparse matrix in data structure
16. Concurrency Control in DBMS
Linked list
Time and space complexity
Binary Search
Binary Tree in Data Structure
Data Structure (Tree)
Array data structure
Binary search tree(bst)
Data Structures : hashing (1)
Ad

Similar to B and B+ tree (20)

PPTX
B best on presentation on tree ppt.pptx
PDF
B Trees and B+ Trees Data structures in Computer Sciences
PPT
109885098-B-Trees-And-B-Trees in data structure.ppt
PPT
B trees and_b__trees
PPTX
B+ trees - Insertion, Deletion
PPT
B trees dbms
PPTX
PPT
Best for b trees
PPT
btrees.ppt ttttttttttttttttttttttttttttt
PPTX
B+ trees and height balance tree
PDF
B TREE ( a to z concept ) in data structure or DBMS
PPTX
presentation for seminar with easiest way
PPTX
Nikhat b+ trees ppt
PPT
B-and-B-Tree-ppt presentation in data structure
PPTX
Presentation on b trees [autosaved]
PDF
Jamal ppt b+tree dbms
PPTX
B+ tree.pptx
PPT
B+tree
PPT
btree.ppt ggggggggggggggggggggggggggggggg
PDF
A41001011
B best on presentation on tree ppt.pptx
B Trees and B+ Trees Data structures in Computer Sciences
109885098-B-Trees-And-B-Trees in data structure.ppt
B trees and_b__trees
B+ trees - Insertion, Deletion
B trees dbms
Best for b trees
btrees.ppt ttttttttttttttttttttttttttttt
B+ trees and height balance tree
B TREE ( a to z concept ) in data structure or DBMS
presentation for seminar with easiest way
Nikhat b+ trees ppt
B-and-B-Tree-ppt presentation in data structure
Presentation on b trees [autosaved]
Jamal ppt b+tree dbms
B+ tree.pptx
B+tree
btree.ppt ggggggggggggggggggggggggggggggg
A41001011
Ad

Recently uploaded (20)

PPTX
Cell Structure & Organelles in detailed.
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
RMMM.pdf make it easy to upload and study
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Insiders guide to clinical Medicine.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
Cell Structure & Organelles in detailed.
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPH.pptx obstetrics and gynecology in nursing
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Microbial disease of the cardiovascular and lymphatic systems
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Week 4 Term 3 Study Techniques revisited.pptx
102 student loan defaulters named and shamed – Is someone you know on the list?
Basic Mud Logging Guide for educational purpose
Renaissance Architecture: A Journey from Faith to Humanism
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
RMMM.pdf make it easy to upload and study
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
Insiders guide to clinical Medicine.pdf
Anesthesia in Laparoscopic Surgery in India

B and B+ tree

  • 1. B AND B+ TREE
  • 3. Definition:-  B-Tree is a generalization of a binary search tree designed especially for use on disk.  So, B-trees used to represent very large dictionaries that reside on disk.  This is the special case of M-Way tree.  B-Tree Consists of Root Node, Branch Node and Leaf Node containing indexed field value in ending nodes of the tree.  B-trees are a good example of a data structure for external memory.  It is commonly used in databases and filesystems.  In order to maintain the pre-defined range, internal nodes may be joined or split.  Each internal node of a B-tree contains a number of keys.  The keys act as separation values which divide its subtrees.  B-trees may waste some space (memory) * Since nodes are not entirely full.  If the B-tree is balanced, its search / insert / add operations take about log(n) steps.
  • 4. Properties of B Tree:- B-Tree of order n  Not empty => root has at least 2 children.  Remaining internal nodes (if any) have at least ceil (m/2) children.  All leaves are at the same depth in the tree.  Non-leaf node with k children has k-1 keys.  It may contain large number of keys.
  • 5. Operation on B+ Tree:-  Searching.  Insertion.  Deletion.
  • 6. Searching:-  In B-Tree search start from Root node but every time we make 2-way decision. Steps for searching :-  Let the key to be searched be k.  Search is similar to search in Binary Search Tree. 1. We start from root and recursively traverse down. 2. For every visited non-leaf node, if the node has key, we simply return the node. 3. Otherwise we recur down to the appropriate child (The child which is just before the first greater key) of the node. 4. If we reach a leaf node and don’t find k in the leaf node, we return NULL.
  • 7. Insertion:-  Steps for insertion :- Let the key to be inserted be k. 1. A new key is always inserted at leaf node. 2. Like BST, we start from root and traverse down till we reach a leaf node. 3. Once we reach a leaf node, we insert the key in that leaf node. Unlike BSTs, we have a predefined range on number of keys that a node can contain. 4. So before inserting a key to node, we make sure that the node has extra space. 5. To insert a new key, we go down from root to leaf. 6. Before traversing down to a node, we first check if the node is full. 7. If the node is full, we split it to create space.
  • 8. Insertion Example :-  key :- 1,12,8,2,25,6,14,28,17,7,52,16,48,68. Order = 5 Procedure for adding key in b-tree Step1. Step2.
  • 10. Deletion:- 1. Deletion from a B-tree is more complicated than insertion, because we can delete a key from any node-not just a leaf. 2. when we delete a key from an internal node, we will have to rearrange the node’s children. 3. Just as we had to ensure that a node didn’t get too big due to insertion 4. we must ensure that a node doesn’t get too small during deletion. 5. a simple approach to deletion might have to back up if a node (other than the root) along the path to where the key is to be deleted has the minimum number of keys. 6. Since most of the keys in a B-tree are in the leaves, deletion operations are most often used to delete keys from leaves. 7. The recursive delete procedure then acts in one downward pass through the tree, without having to back up. 8. When deleting a key in an internal node, however, the procedure makes a downward pass through the tree but may have to return to the node from which the key was deleted to replace the key with its predecessor or successor. 9. No of children must be according to the ceil of m/2.
  • 15. Analysis Of B Tree  For a B-Tree of order M 1. Each internal node has up to M-1 keys to search 2. Each internal node has between M/2 and M children 3. Depth of B-Tree storing N items is O(log M/2 N)  Find: Run time is: 1. O(log M) to binary search which branch to take at each node. But M is small compared to N. 2. Total time to find an item is O(depth*log M) = O(log N)
  • 17. Definition:-  The most commonly implemented form of the B-Tree is the B+-Tree.  The order of the B+ tree determines the number of subtrees, which exactly follows the B-Tree definition.  A B+ tree is a data structure often used in the implementation of database indexes.  Only Leaf nodes store references to data.  A leaf node may store more or less data records than an internal node stores keys.  It contains index pages and data pages.  The data pages always appear as leaf nodes in the tree.  The root node and intermediate nodes are always index pages.
  • 18. Properties of B+ Tree:- For a B-tree of order m:  All data are on the same level.  If a B+ tree consists of a single node, then the node is both a root and a leaf.  Each internal node other than the root contains between m/2 search keys.  The capacity of a leaf has to be 50% or more.
  • 19. Operation on B+ Tree:-  Searching.  Insertion.  Deletion.
  • 20. Searching:- 1. Searching just like in a binary search tree. 2. Starts at the root, works down to the leaf level. 3. Does a comparison of the search value and the current “separation value”, goes left or right. 4. Since no structure change in a B+ tree during a searching process. 5. So just compare the key value with the data in the tree, then give the result back.
  • 21. Insertion:- 1. A search is first performed, using the value to be added. 2. After the search is completed, the location for the new value is known. 3. If the tree is empty, add to the root. 4. Once the root is full, split the data into 2 leaves, using the root to hold keys and pointers. 5. If adding an element will overload a leaf, take the median and split it.
  • 22. Insertion Example :-  Example #1: insert 28 into the below tree. Result:-
  • 23.  Example #2: insert 70 into below tree Result:-
  • 24.  Example #3: insert 95 into below tree Result:-
  • 25. Deletion:- 1. Deletion, like insertion, begins with a search. 2. When the item to be deleted is located and removed, the tree must be checked to make sure no rules are violated. 3. The rule to focus on is to ensure that each node has at least ceil (n/2) pointers.
  • 26. Deletion Example :-  Example #1: delete 70 from the tree Result:-
  • 27.  Example #2: delete 25 from below tree Result:- Replace 25 with 28 in the index page. On Next Slide…
  • 29.  Example #3: delete 60 from the below tree Result:-
  • 30. Analysis Of B+ Tree  For a B+-Tree Searching Operation:- 1. During the search operation, h nodes are read from the disk to the main memory where h is the height of the B+-tree. 2. So, the height of the B+-tree is h = O(logn), and the time complexity of each linear search is O(t), Thus, the total time complexity of the B+-tree search operation is O(t logt n).  For a B+-Tree Insertion Operation:- 1. The time complexity of the insertion algorithm is O(t · logtn). 2. where the cofficient t is due to the operations performed for each node in the main memory.
  • 31. Analysis Of B+ Tree  For a B+-Tree Deletion Operation:- 1. The time complexity of the insertion algorithm is O(t · logtn). 2. Each time we encounter a node having exactly t children (non-leaf node) or keys (leaf node)