SlideShare a Scribd company logo
A multiway tree of order m is an ordered tree where each node
has at most m children. For each node, if k is the actual number of
children in the node, then k - 1 is the number of keys in the node.
If the keys and subtrees are arranged in the fashion of a search
tree, then this is called a multiway search tree of order m. For
example, the following is a multiway search tree of order 4. Note
that the first row in each node shows the keys, while the second
row shows the pointers to the child nodes. Of course, in any
useful application there would be a record of data associated with
each key, so that the first row in each node might be an array of
records where each record contains a key and its associated data.
Another approach would be to have the first row of each node
contain an array of records where each record contains a key and
a record number for the associated data record, which is found in
another file. This last method is often used when the data records
are large. The example software will use the first method.
typedef struct { int Count; // number of keys stored in the
current node ItemType Key[3]; // array to hold the 3 keys [4];
long Branch[4]; // array of fake pointers (record numbers) }
NodeType;
Then a multiway search tree of order 4 has to fulfill the following
conditions related to the ordering of the keys:
•The keys in each node are in ascending order.
•At every given node (call it Node) the following is true:
•The subtree starting at record Node.Branch[0] has only keys
that are less than Node.Key[0].
•The subtree starting at record Node.Branch[1] has only keys
that are greater than Node.Key[0] and at the same time less
than Node.Key[1].
•The subtree starting at record Node.Branch[2] has only keys
that are greater than Node.Key[1] and at the same time less
than Node.Key[2].
•The subtree starting at record Node.Branch[3] has only keys
that are greater than Node.Key[2].
Note that if less than the full number of keys are in the Node,
these 4 conditions are truncated so that they speak of the
appropriate number of keys and branches.
ll leaves are on the bottom level.
ll internal nodes (except perhaps the root
node) have at least ceil(m / 2) (nonempty)
children.
he root node can have as few as 2
children if it is an internal node, and can
obviously have no children if the root node
is a leaf (that is, the whole tree consists
only of the root node).
A B-tree of order m is a multiway search tree of order m such that:
Note that ceil(x) is the so-called ceiling function. It's value is the smallest integer that is
greater than or equal to x. Thus ceil(3) = 3, ceil(3.35) = 4, ceil(1.98) = 2, ceil(5.01) = 6,
ceil(7) = 7, etc.
A B-tree is a fairly well-balanced tree by virtue of the fact that all leaf nodes must be at
the bottom. Condition (2) tries to keep the tree fairly bushy by insisting that each node
have at least half the maximum number of children. This causes the tree to "fan out" so
that the path from root to leaf is very short even in a tree that contains a lot of data.
Let's work our way through an example similar to that given by
Kruse. 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 means that a node can have a maximum of 5 children
and 4 keys. All nodes other than the root must have a minimum of
2 keys. The first 4 letters get inserted into the same node,
resulting in this picture:
When we try to insert the H, we find no room in this node, so we
split it into 2 nodes, moving the median item G up into a new root
node. Note that in practice we just leave the A and C in the
current node and place the H and N into a new node to the right of
the old one.
Inserting E, K, and Q proceeds without requiring any splits:
Inserting M requires a split. Note that M happens to be the median key and so is moved up into
the parent node.
The letters F, W, L, and T are then added without needing any
split.
When Z is added, the rightmost leaf must be split. The median item T is moved
up into the parent node. Note that by moving up the median key, the tree is
kept fairly balanced, with 2 keys in each of the resulting nodes.
The insertion of D causes the leftmost leaf to be split. D happens to be the
median key and so is the one moved up into the parent node. The letters P, R,
X, and Y are then added without any need of splitting:
Finally, when S is added, the node with N, P, Q, and R splits,
sending the median Q up to the parent. However, the parent node
is full, so it splits, sending the median M up to form a new root
node. Note how the 3 pointers from the old parent node stay in the
revised node that contains D and G.
Deleting an Item
In the B-tree as we left it at the end of the last section, delete H. Of course, we first do a
lookup to find H. Since H is in a leaf and the leaf has more than the minimum number of
keys, this is easy. We move the K over where the H had been and the L over where the K
had been. This gives
Next, delete the T. Since T is not in a leaf, we find its successor (the next item in ascending
order), which happens to be W, and move W up to replace the T. That way, what we really have
to do is to delete W from the leaf, which we already know how to do, since this leaf has extra
keys. In ALL cases we reduce deletion to a deletion in a leaf, by using this method
Next, delete R. Although R is in a leaf, this leaf does not have an extra key; the deletion results in a
node with only one key, which is not acceptable for a B-tree of order 5. If the sibling node to the
immediate left or right has an extra key, we can then borrow a key from the parent and move a key up
from this sibling. In our specific case, the sibling to the right has an extra key. So, the successor W of
S (the last key in the node where the deletion occurred), is moved down from the parent, and the X is
moved up. (Of course, the S is moved over so that the W can be inserted in its proper place.)
Btree
Finally, let's delete E. This one causes lots of problems. Although E is in a leaf, the leaf has no
extra keys, nor do the siblings to the immediate right or left. In such a case the leaf has to be
combined with one of these two siblings. This includes moving down the parent's key that was
between those of these two leaves. In our example, let's combine the leaf containing F with the leaf
containing A C. We also move down the D.
We begin by finding the immediate successor, which would be D,
and move the D up to replace the C. However, this leaves us with
a node with too few keys.
Btree
Btree

More Related Content

PPT
PPT
08 B Trees
PPT
Binary search trees
PPT
B trees and_b__trees
PPT
B Trees
PPTX
B and B+ tree
PPT
Best for b trees
PPT
B trees and_b__trees
08 B Trees
Binary search trees
B trees and_b__trees
B Trees
B and B+ tree
Best for b trees
B trees and_b__trees

What's hot (20)

PPT
2-3 trees in c++
PPT
Binary trees
PPTX
B+ trees and height balance tree
PPT
B trees dbms
PPT
Binary search tree(bst)
PDF
Binary Search Tree
PPT
Binary search trees
PPT
b+ tree
PPT
DOCX
Roots of polynomials
PDF
CMSC 350 HOMEWORK 3
PPTX
B+tree Data structures presentation
PPT
binary search tree
PPTX
Nikhat b+ trees ppt
PDF
6th Math (C2) - Inv. #4--Dec13
PPT
1.5 binary search tree
PPTX
Lecture 8 data structures and algorithms
PDF
BinarySearchTree-bddicken
PPTX
B tree
2-3 trees in c++
Binary trees
B+ trees and height balance tree
B trees dbms
Binary search tree(bst)
Binary Search Tree
Binary search trees
b+ tree
Roots of polynomials
CMSC 350 HOMEWORK 3
B+tree Data structures presentation
binary search tree
Nikhat b+ trees ppt
6th Math (C2) - Inv. #4--Dec13
1.5 binary search tree
Lecture 8 data structures and algorithms
BinarySearchTree-bddicken
B tree
Ad

Similar to Btree (20)

PPT
B-and-B-Tree-ppt presentation in data structure
PPTX
B trees2
PPT
109885098-B-Trees-And-B-Trees in data structure.ppt
PPT
BTrees-fall2010.ppt
PPT
b-trees a tree non linear data structure.ppt
PPTX
B+ tree.pptx
PPT
16807097.ppt b tree are a good data structure
PPT
B tree by-jash acharya
PDF
Makalah if2091-2011-020
PPTX
Lecture 11 data structures and algorithms
PPTX
PPT
B tree and application B tree and application
PPT
b-tree.ppt
PPT
M.E - Computer Science and Engineering-Data structure B tree
PPTX
Presentation on b trees [autosaved]
PPT
Multiway Trees.ppt
PPTX
10.m way search tree
PPTX
B+ trees - Insertion, Deletion
PPT
4-b-tree.ppt
B-and-B-Tree-ppt presentation in data structure
B trees2
109885098-B-Trees-And-B-Trees in data structure.ppt
BTrees-fall2010.ppt
b-trees a tree non linear data structure.ppt
B+ tree.pptx
16807097.ppt b tree are a good data structure
B tree by-jash acharya
Makalah if2091-2011-020
Lecture 11 data structures and algorithms
B tree and application B tree and application
b-tree.ppt
M.E - Computer Science and Engineering-Data structure B tree
Presentation on b trees [autosaved]
Multiway Trees.ppt
10.m way search tree
B+ trees - Insertion, Deletion
4-b-tree.ppt
Ad

More from sharmili priyadarsini (20)

Recently uploaded (20)

PPTX
Introduction to pro and eukaryotes and differences.pptx
PDF
IGGE1 Understanding the Self1234567891011
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PDF
1_English_Language_Set_2.pdf probationary
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
advance database management system book.pdf
PDF
My India Quiz Book_20210205121199924.pdf
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PPTX
Virtual and Augmented Reality in Current Scenario
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PDF
Hazard Identification & Risk Assessment .pdf
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PDF
What if we spent less time fighting change, and more time building what’s rig...
PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
Introduction to pro and eukaryotes and differences.pptx
IGGE1 Understanding the Self1234567891011
202450812 BayCHI UCSC-SV 20250812 v17.pptx
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
1_English_Language_Set_2.pdf probationary
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
advance database management system book.pdf
My India Quiz Book_20210205121199924.pdf
LDMMIA Reiki Yoga Finals Review Spring Summer
Virtual and Augmented Reality in Current Scenario
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
A powerpoint presentation on the Revised K-10 Science Shaping Paper
Practical Manual AGRO-233 Principles and Practices of Natural Farming
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
Unit 4 Computer Architecture Multicore Processor.pptx
Hazard Identification & Risk Assessment .pdf
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
What if we spent less time fighting change, and more time building what’s rig...
B.Sc. DS Unit 2 Software Engineering.pptx

Btree

  • 1. A multiway tree of order m is an ordered tree where each node has at most m children. For each node, if k is the actual number of children in the node, then k - 1 is the number of keys in the node. If the keys and subtrees are arranged in the fashion of a search tree, then this is called a multiway search tree of order m. For example, the following is a multiway search tree of order 4. Note that the first row in each node shows the keys, while the second row shows the pointers to the child nodes. Of course, in any useful application there would be a record of data associated with each key, so that the first row in each node might be an array of records where each record contains a key and its associated data. Another approach would be to have the first row of each node contain an array of records where each record contains a key and a record number for the associated data record, which is found in another file. This last method is often used when the data records are large. The example software will use the first method.
  • 2. typedef struct { int Count; // number of keys stored in the current node ItemType Key[3]; // array to hold the 3 keys [4]; long Branch[4]; // array of fake pointers (record numbers) } NodeType;
  • 3. Then a multiway search tree of order 4 has to fulfill the following conditions related to the ordering of the keys: •The keys in each node are in ascending order. •At every given node (call it Node) the following is true: •The subtree starting at record Node.Branch[0] has only keys that are less than Node.Key[0]. •The subtree starting at record Node.Branch[1] has only keys that are greater than Node.Key[0] and at the same time less than Node.Key[1]. •The subtree starting at record Node.Branch[2] has only keys that are greater than Node.Key[1] and at the same time less than Node.Key[2]. •The subtree starting at record Node.Branch[3] has only keys that are greater than Node.Key[2]. Note that if less than the full number of keys are in the Node, these 4 conditions are truncated so that they speak of the appropriate number of keys and branches.
  • 4. ll leaves are on the bottom level. ll internal nodes (except perhaps the root node) have at least ceil(m / 2) (nonempty) children. he root node can have as few as 2 children if it is an internal node, and can obviously have no children if the root node is a leaf (that is, the whole tree consists only of the root node). A B-tree of order m is a multiway search tree of order m such that: Note that ceil(x) is the so-called ceiling function. It's value is the smallest integer that is greater than or equal to x. Thus ceil(3) = 3, ceil(3.35) = 4, ceil(1.98) = 2, ceil(5.01) = 6, ceil(7) = 7, etc. A B-tree is a fairly well-balanced tree by virtue of the fact that all leaf nodes must be at the bottom. Condition (2) tries to keep the tree fairly bushy by insisting that each node have at least half the maximum number of children. This causes the tree to "fan out" so that the path from root to leaf is very short even in a tree that contains a lot of data.
  • 5. Let's work our way through an example similar to that given by Kruse. 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 means that a node can have a maximum of 5 children and 4 keys. All nodes other than the root must have a minimum of 2 keys. The first 4 letters get inserted into the same node, resulting in this picture:
  • 6. When we try to insert the H, we find no room in this node, so we split it into 2 nodes, moving the median item G up into a new root node. Note that in practice we just leave the A and C in the current node and place the H and N into a new node to the right of the old one. Inserting E, K, and Q proceeds without requiring any splits:
  • 7. Inserting M requires a split. Note that M happens to be the median key and so is moved up into the parent node. The letters F, W, L, and T are then added without needing any split.
  • 8. When Z is added, the rightmost leaf must be split. The median item T is moved up into the parent node. Note that by moving up the median key, the tree is kept fairly balanced, with 2 keys in each of the resulting nodes. The insertion of D causes the leftmost leaf to be split. D happens to be the median key and so is the one moved up into the parent node. The letters P, R, X, and Y are then added without any need of splitting:
  • 9. Finally, when S is added, the node with N, P, Q, and R splits, sending the median Q up to the parent. However, the parent node is full, so it splits, sending the median M up to form a new root node. Note how the 3 pointers from the old parent node stay in the revised node that contains D and G.
  • 10. Deleting an Item In the B-tree as we left it at the end of the last section, delete H. Of course, we first do a lookup to find H. Since H is in a leaf and the leaf has more than the minimum number of keys, this is easy. We move the K over where the H had been and the L over where the K had been. This gives
  • 11. Next, delete the T. Since T is not in a leaf, we find its successor (the next item in ascending order), which happens to be W, and move W up to replace the T. That way, what we really have to do is to delete W from the leaf, which we already know how to do, since this leaf has extra keys. In ALL cases we reduce deletion to a deletion in a leaf, by using this method Next, delete R. Although R is in a leaf, this leaf does not have an extra key; the deletion results in a node with only one key, which is not acceptable for a B-tree of order 5. If the sibling node to the immediate left or right has an extra key, we can then borrow a key from the parent and move a key up from this sibling. In our specific case, the sibling to the right has an extra key. So, the successor W of S (the last key in the node where the deletion occurred), is moved down from the parent, and the X is moved up. (Of course, the S is moved over so that the W can be inserted in its proper place.)
  • 13. Finally, let's delete E. This one causes lots of problems. Although E is in a leaf, the leaf has no extra keys, nor do the siblings to the immediate right or left. In such a case the leaf has to be combined with one of these two siblings. This includes moving down the parent's key that was between those of these two leaves. In our example, let's combine the leaf containing F with the leaf containing A C. We also move down the D.
  • 14. We begin by finding the immediate successor, which would be D, and move the D up to replace the C. However, this leaves us with a node with too few keys.