Lesson 04
Lesson 04
SYSTEMS
ICT3273
B+ Tree
Nuwan Laksiri
Department of ICT
Faculty of Technology
University of Ruhuna Lecture 04
WHAT WE DISCUSS TODAY ……..
• RECAP INDEXING
NEXT WEEK
• QUERY PROCESSING
RECAP
• INDEXING
TREE
TREE
TREE
BINARY TREE
SELF BALANCING TREE
m-WAY SEARCH TREE
• The m-way search trees are multi-way trees which are
generalized versions of binary trees where each node contains
multiple elements.
• In an m-Way tree of order m, each node contains a maximum
of m – 1 elements and m children.
B TREE
• B Tree is a specialized m-way tree that can be widely used for disk
access. A B-Tree of order m can have at most m-1 keys and m
children. One of the main reason of using B tree is its capability to
store large number of keys in a single node and large key values by
keeping the height of the tree relatively small.
• A B tree of order m contains all the properties of an M way tree. In
addition, it contains the following properties.
• Every node in a B-Tree contains at most m children.
• Every node in a B-Tree except the root node and the leaf node contain
at least m/2 children.
• The root nodes must have at least 2 nodes.
• All leaf nodes must be at the same level.
• It is not necessary that, all the nodes contain the same number of
children but, each node must have m/2 number of nodes.
B TREE OPERATIONS
• Search
• Searching in B Trees is similar to that in Binary search tree.
• Insert
• Traverse the B Tree in order to find the appropriate leaf node at which
the node can be inserted.
• If the leaf node contain less than m-1 keys then insert the element in the
increasing order.
• Else, if the leaf node contains m-1 keys, then follow the following steps.
• Insert the new element in the increasing order of elements.
• Split the node into the two nodes at the median.
• Push the median element upto its parent node.
• If the parent node also contain m-1 number of keys, then split it too by
following the same steps.
• Delete
B TREE OPERATIONS
Deletion is also performed at the leaf nodes. The node which is to be deleted can either be a leaf
node or an internal node. Following algorithm needs to be followed in order to delete a node
from a B tree.
• Locate the leaf node.
• If there are more than m/2 keys in the leaf node then delete the desired key from the
node.
• If the leaf node doesn't contain m/2 keys then complete the keys by taking the element
from right or left sibling.
• If the left sibling contains more than m/2 elements then push its largest element up
to its parent and move the intervening element down to the node where the key is
deleted.
• If the right sibling contains more than m/2 elements then push its smallest element up
to the parent and move intervening element down to the node where the key is
deleted.
• If neither of the sibling contain more than m/2 elements then create a new leaf node by
joining two leaf nodes and the intervening element of the parent node.
• If parent is left with less than m/2 nodes then, apply the above process on the parent too.
If the node which is to be deleted is an internal node, then replace the node with its in-order
successor or predecessor. Since, successor or predecessor will always be on the leaf node
hence, the process will be similar as the node is being deleted from the leaf node.
INTRODUCTION: B+ TREE
• B+ tree is a storage method in a tree like structure
• B+ trees are used in DBMS for accessing and organizing data
more efficiently
• B+ tree is a balanced binary search tree. It follows a multi-
level index format
• B+ trees are dynamic. The height of the tree grows and
contracts as records are added and deleted
• The keys in the tree are ordered
• It supports efficient equality and range search
BASICS OF B+ TREE
• B+ tree has one root, internal nodes and leaf nodes
• All leaf nodes will have the actual records stored. If we have to
search for any record, they are all found at leaf node
• Internal nodes will have only pointers to the leaf nodes; it not
has any data
• Every path from the root of the tree to a leaf is of the same
length
• Every leaf node of the B+ tree contains one block pointer P to
point to next leaf node
• It contains index pages and data pages
BASICS OF B+ TREE
STRUCTURE OF A B+ TREE
STRUCTURE OF A B+ TREE
STRUCTURE OF A B+ TREE (PAGE FORMAT)
STRUCTURE OF A B+ TREE (PAGE FORMAT)
STRUCTURE OF A B+ TREE
EXAMPLE B+ TREE
B+ TREE PROPERTIES
• Balanced tree
• Every node except root must be at least ½ full
• Recap INDEXING
• B+ Tree
• B+ Tree Operations
• Search
• Insert
• Delete
REFERENCES