0% found this document useful (0 votes)
28 views

B + 5 Tree

This document discusses B+ trees, which are a data structure used to store sorted data like keys in a way that allows for efficient searches, insertions, and deletions. B+ trees have internal nodes that contain keys to direct searching and leaf nodes that store the actual data. The document explains the structure and rules of B+ trees and how insertions and deletions are performed while maintaining the tree's balance and ordering properties.

Uploaded by

Shah Anaam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

B + 5 Tree

This document discusses B+ trees, which are a data structure used to store sorted data like keys in a way that allows for efficient searches, insertions, and deletions. B+ trees have internal nodes that contain keys to direct searching and leaf nodes that store the actual data. The document explains the structure and rules of B+ trees and how insertions and deletions are performed while maintaining the tree's balance and ordering properties.

Uploaded by

Shah Anaam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

B+ TREES

Presented by-Anamul Showkat


Rollno.:- 2023CUKmr01
What actually is B+ Tree?
➢ It's an another n-ary Tree (Generic trees)

➢ It actually is an optimization of B tree.

➢ Contains root, internal nodes and leaf nodes like other Trees.

➢ Internal nodes contains router value of data in leaves.

➢ All data is stored at leaf level.

➢ Leaf nodes are linked to each other.


Rules for B+ Tree
➢ Leaves are used to store data records.

➢ Stored in the internal nodes of the Tree.

➢ If a target key value is less than the internal node, then the point just to its
left side is followed.

➢ If a target key value is greater than or equal to the internal node, then the
point just to its right side is followed.

➢ The root has a minimum of two children.


Insertion in B+ Tree
During insertion following properties of B+ Tree must be followed:
➢ Each node except root can have a maximum of M children and at
least (M/2) children.
➢ Each node can contain a maximum of M – 1 keys and a minimum
of (M/2) – 1 keys.
➢ The root has at least two children and at-least one search key.
➢ While insertion overflow of the node occurs when it contains more
than M – 1 search key values.
Here M is the order of B+ tree.
Steps for insertion in B+ Tree
➢ Every element is inserted into a leaf node. So, go to the appropriate leaf node.
➢ Insert the key into the leaf node in increasing order only if there is no overflow.
➢ If there is an overflow go ahead with the following steps mentioned in B+ Tree
properties.
Insertion B+ Tree
Case 1: Overflow in leaf node
➢ Split the leaf node into two nodes.

➢ First node contains (m-1)/2) values.

➢ Second node contains the remaining values.

➢ Copy the smallest search key value from second node to the
parent node.(Right biased)
Insertion B+ Tree
Ex. Inserting 8 into B+ Tree of order of 5:
Insertion B+ Tree
Case 2: Overflow in non-leaf node
➢ Split the non-leaf node into two nodes.

➢ First node contains (m/2)-1 values.

➢ Move the smallest among remaining to the parent.

➢ Second node contains the remaining keys.


Insertion B+ Tree
Ex. Inserting 15 into B+ Tree of order of 5:
Deletion in B+ Tree
➢ Delete key and data from leaf page.

➢ If leaf page underflows, merge with sibling and delete key in between them.

➢ If index page underflows, merge with sibling and move down key in between them

Ex. Order (m) = 4


Max children = 4
Min children = 2
Max Keys = 3
Min Keys = 1
Data: 21,31,20,10,7,25,42
Delete: 31
Deletion in B+ Tree
20
To delete 31, we have
to check at both the
Index and the Leaf
7 17 25 31 node level for the data
31 and delete from
both places.

1 4 7 10 7 9 20 25 28 31 42
Deletion in B+ Tree
New Index and
nodes will be like
this after deletion

20
25 ?

7 17 25 42
25 28 42

1 4 7 10 7 9 20 25 28 42

For the empty Index, we will


look at the right child and
take the minimum value and
place it in the index.
Searching in B+ Trees

Ex. Let us suppose we have to find 58 in the B+ Tree.


➢ We will start by fetching from the root node then we will move
to the leaf node, which might contain a record of 58.
➢ In the image given above, we will get 58 between 50 and 70.
➢ Therefore, we will we are getting a leaf node in the third leaf
node and get 58 there.
➢ If we are unable to find that node, we will return that ‘record not
founded’ message.
Time Complexity

Where b = order
n = number of keys in the tree
Features of B+ Tree
Balanced: Self-balancing, means that as data is added or removed from the tree,
Multi-level: Multi-level data structures, with a root node at the top and one or more levels of internal
nodes below it. The leaf nodes at the bottom level contain the actual data.
Ordered: Maintain the order of the keys in the tree, which makes it easy to perform range queries
and other operations that require sorted data.
Fan-out: Have a high fan-out, means each node can have many child nodes, that reduces the height
of the tree and increases the efficiency of searching and indexing operations.
Cache-friendly: Designed to be cache-friendly, which means that they can take advantage of the
caching mechanisms to improve performance.
Disk-oriented: B+ Trees are often used for disk-based storage systems because they are efficient at
storing and retrieving data from disk.
THANKYOU

You might also like