Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 17

B+TREE:CREATION

INSERTION AND
DELECTION
BY GROUP :- B5
-HARSH MODI
-HARSH PATEL
-ISHAN BHAGAT
-RISHI MODI
 ABOUT TREE

 A tree is a nonlinear data structure compared to array


, linked list ,stack and queues
 A tree is a widely used abstract data types that
simulates a hierarchical tree structure.
 The starting of the tree is the “Root node” and the
reference nodes are the “children” of that nodes.
 BASIC TERMINOLOGY’S
• Order of tree:-The maximum number of keys in a
record is called the order of the B+ tree
• Root node :-The root node R is the topmost node in the
tree. If R = NULL, then it means the tree is empty.
• Sub tree:- If the root node R is not NULL, then the
trees T1, T2, and T3 are called the sub-trees of R.
• Leaf node :-A node that has no children is called the
leaf node or the terminal nodes
• Keys :- Each node contain a key and two sub trees.
• Path:- A sequence of consecutive edges is called a path
• Degree :-Degree of a node is equal to the number of
children that a node has. The degree of a leaf node is
zero
 APPLICATION OF TREES:

• Trees are used to store simple as well as complex data


• Trees are often used for implementing other types of data structures like hash
tables, sets and maps
• Trees are an important data structure used for compiler construction.
• Trees are also used in database design.
• Trees are used in file system directories.
• Trees are also widely used for information storage and retrieval in symbol
tables.
 B + TREE:
• A B+ tree is a variant of a B tree which stores sorted data in a way that allows
for efficient insertion, retrieval, and removal of records.
• A B+ tree is a balanced tree in which every path from the root of the tree to a
leaf is to the same length.
• Each node can have at most m key fields and m+1 pointer fields
• Half-full must be satisfied (except root node):
• m is even and m=2d – Leaf node half full: at least d entries – Non-leaf node
half full: at least d entries
• m is odd and m = 2d+1 – Leaf node half full: at least d+1 entries – Non-leaf
node half full: at least d entries (i.e., d+1 pointers)
 INSERTION OF B+ TREE
Step 1: Insert the new node as the leaf node.
Step 2: If the leaf node overflows, split the node and copy the middle element to
next index node.
Step 3: If the index node overflows, split that node and move the middle element
to next index page
EXAMPLE OF INSERTIONS IN B+
TREE

• Suppose each B+-tree node can hold up to 4 pointers and 3 keys.


• m=3 (odd), d=1
• Half-full (for odd m value) – Leaf node, at least 2 (d+1) entries – Non-leaf
nodes, at least 2 (d+1) pointers (1 entry)
• Insert 1, 3, 5, 7, 9, 2, 4, 6, 8, 10
Insert 1, 3, 5, 7, 9, 2, 4, 6, 8, 10
• Insert 1
1

• Insert 3, 5
1 3 5

•Insert 7

1 3 5 7

• Insert 9
5

1 3 5 7 9
• Insert 2 5

1 2 3 5 7 9
• Insert 4
3 5

1 2 3 4 5 7 9
• Insert 6
3 5 7

1 2 3 4 5 6 7 9

• Insert 8
3 5 7

3 5 7 3 4 5 6 7 8 9
• Insert 10 7

3 5 9

7 8 9 10

1 2 3 4 5 6
 DELETION OF B+ TREE

Step 1: Delete the key and data from the leaves.


Step 2: If the leaf node underflows, merge that node with the sibling and delete
the key in between them.
Step 3: If the index node underflows, merge that node with the sibling and move
down the key in between them.
EXAMPLE OF DELETIONS IN B+
TREE
Let our B+ tree 7

3 5 9

7 8 9 10

1 2 3 4 5 6

Delete 9,8,7,3,4,2 from our B+ tree


After removing 9 from our B+ tree:
7

3 5 10

1 2 3 4 5 6 7 8 10

After removing 8 from B+ tree: 7

3 5 10

1 2 3 4 5 6 7 10

5
After removing 7 from B+ tree:

3 10

1 2 3 4 5 6 10
After removing 3 from our B+ Tree: 5

4 10

1 2 4 5 6 10

After removing 4 from our B+ Tree: 5

2 10

1 2 5 6 10
After removing 2 from our B+ Tree:
5 10

1 5 6 10
 CHARACTERISTICS OF B +
TREE
 Data records are only stored in the leaf nodes .
 Internal nodes store just keys .
 All leaf nodes are interconnect with each other ,leaf nodes for faster access.
 Keys are used for directing a search to the proper node ,then the pointer just to
its left is followed .
 IF a target key is less than a key in an internal node , then the pointer just to its left
is followed .
 If a target key is greater or equal to the key in the internal node ,then the pointer
to its right followed
 B+ tree combines feature of ISAM (Indexed Sequential Access Method)and B
tree.
 ADVANTAGE OF B + TREE

• A B+ tree can be thought of as a multi-level index in which the leaves make


up a dense index and the non-leaf nodes make up a sparse index. The
advantages of B+ trees can be given as follows:
• 1. Records can be fetched in equal number of disk accesses
• 2. It can be used to perform a wide range of queries easily as leaves are
linked to nodes at the
• upper level
• 3. Height of the tree is less and balanced
• 4. Supports both random and sequential access to records
• 5. Keys are used for indexing

You might also like