B Tree
B Tree
1. "B-tree" stands for "balanced tree," which means that the tree attempts to keep all levels
approximately the same height to ensure efficient operations.
2. A B-tree is a self-balancing search tree data structure that maintains sorted data and
allows efficient insertion, deletion, and search operations.
3. It is commonly used in file systems and databases to store and retrieve large amounts of
data.
4. In B-tree each node can contain more than one key and can have more than two children
5. It is a generalized form of the binary search tree.it is also known as a height-balanced m-
way tree.
PROPERTIES.
ADVANTAGES
DISADVANTAGES
Increased Complexity
Higher Memory Overhead
B Tree Applications
Advantages of B+ Tree
S B Tree B+ Tree
N
1 Search keys can not be repeatedly stored. Redundant search keys can be present.
2 Data can be stored in leaf nodes as well Data can only be stored on the leaf
as internal nodes nodes.
3 Searching for some data is a slower Searching is comparatively faster as
process since data can be found on data can only be found on the leaf
internal nodes as well as on the leaf nodes.
nodes.
4 Deletion of internal nodes are so Deletion will never be a complexed
complicated and time consuming. process since element will always be
deleted from the leaf nodes.
5 Leaf nodes can not be linked together. Leaf nodes are linked together to make
the search operations more efficient.
AVL TREE
AVL Tree can be defined as height balanced binary search tree in which
each node is associated with a balance factor which is calculated by
subtracting the height of its right sub-tree from that of its left sub-tree.
If balance factor of any node is 0, it means that the left sub-tree and right
sub-tree contain equal height.
If balance factor of any node is -1, it means that the left sub-tree is one level
lower than the right sub-tree.
EXAMPLE
AVL Tree Rotations
In AVL tree, after performing operations like insertion and deletion we need to
check the balance factor of every node in the tree. If every node satisfies the
balance factor condition then we conclude the operation otherwise we must make it
balanced. Whenever the tree becomes imbalanced due to any operation we
use rotation operations to make the tree balanced.
In RR Rotation, every node moves one position to right from the current position.
To understand RR Rotation, let us consider the following insertion operation in
AVL Tree
Complexity
1. It is difficult to implement.
2. It has high constant factors for some of the operations.
3. Less used compared to Red-Black trees.
4. Due to its rather strict balance, AVL trees provide complicated insertion and
removal operations as more rotations are performed.
5. Take more processing for balancing
Splay Tree
1. Splay Tree is a self - adjusted Binary Search Tree in which every operation
on element rearranges the tree so that the element is placed at the root
position of the tree.
2. Every Splay tree must be a binary search tree but it is need not to be
balanced tree.
3. In a splay tree, every operation is performed at the root of the tree. All the
operations in splay tree are involved with a common operation
called "Splaying".
4. In splay tree, to splay any element we use the following rotation operations...
1. Zig Rotation
2. Zag Rotation
3. Zig - Zig Rotation
Zig Rotation
The Zig Rotation in splay tree is similar to the single right rotation in AVL Tree
rotations. In zig rotation, every node moves one position to the right from its
current position. Consider the following example
Zag Rotation
The Zag Rotation in splay tree is similar to the single left rotation in AVL Tree
rotations. In zag rotation, every node moves one position to the left from its current
position. Consider the following example
Zig-Zig Rotation
Zag-Zag Rotation
Zag-Zig Rotation
Splaying ensures that frequently accessed elements stay near the root of the
tree so that they are easily accessible..
The average case performance of splay trees is comparable to other fully-
balanced trees: O(log n).
Splay trees do not need bookkeeping data; therefore, they have a small
memory footprint.
Disadvantages
Caching
Database Indexing
File Systems
Data Compression
Text Processing
Graph Algorithms
Online Gaming