Trees

You might also like

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

Unit- 3

AVL trees
AVL trees are binary search trees in which the difference between
the height of the left and right subtree is either -1, 0, or +1.

AVL trees are also called a self-balancing binary search tree.


These trees help to maintain the logarithmic search time. It is
named after its inventors (AVL) Adelson, Velsky, and Landis.

 Balance Factor = (Height of Left Subtree - Height of Right


Subtree)

https://www.javatpoint.com/insertion-in-avl-tree
Rotations
Left – Left Rotation
Right – Right Rotation
Right – Left Rotation
Left – Right Rotation

https://
www.tutorialspoint.com/data_structures_a
lgorithms/avl_tree_algorithm.htm
Insertion
Deletion(from right sub tree)
Advantages of AVL Trees

The height of the AVL tree is always


balanced. The height never grows beyond
log N, where N is the total number of
nodes in the tree.
It gives better search time complexity
when compared to simple Binary Search
trees.
AVL trees have self-balancing
capabilities.
B Tree
B Trees is similar to that in Binary search
tree
B-Tree is a self-balanced search tree in
which every node contains multiple keys
and has more than two children.
Operations
Insertion
Deletion
Search
Properties
All leaves are at the same level.
A B-Tree is defined by the term minimum degree ‘t’. The value of t
depends upon disk block size.
Every node except root must contain at least (ceiling)([t-1]/2) keys. The
root may contain minimum 1 key.
All nodes (including root) may contain at most t – 1 keys.
Number of children of a node is equal to the number of keys in it plus 1.
All keys of a node are sorted in increasing order. The child between two
keys k1 and k2 contains all keys in the range from k1 and k2.
B-Tree grows and shrinks from the root which is unlike Binary Search
Tree. Binary Search Trees grow downward and also shrink from
downward.
Like other balanced Binary Search Trees, time complexity to search, insert
and delete is O(log n).
Insertion of a Node in B-Tree happens only at Leaf Node
https://
www.youtube.com/watch?v=KnXohGgIp
QU

http://
www.btechsmartclass.com/data_structures
/b-trees.html
B + Tree
B+ tree is used to store the records very
efficiently by storing the records in an indexed
manner using the B+ tree indexed structure. Due
to the multi-level indexing, the data accessing
becomes faster and easier
In the B+ tree, keys are the indexes stored in the
internal nodes and records are stored in the leaf
nodes.
Properties
All leaves are at the same level. 
The root has at least two children.
 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.
https://
www.javatpoint.com/b-tree-vs-bplus-tree
https://
www.youtube.com/watch?v=jpS8BLb8Bg
I
Heaps
A Heap is a special Tree-based data
structure in which the tree is a complete
binary tree

Types
1. Max heap
2. Min heap
Applications
Heap Implemented priority queues are
used in Graph algorithms like 
Prim’s Algorithm (minimum spanning
tree) and Dijkstra’s algorithm(shortest
path)
Heap sort
Huffman encoding(data compression)

You might also like