Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

General tree:

A tree is an acyclic graph, which means it has no cycles. A chain, also known as a general tree, is a non-
empty finite set of elements known as vertices or nodes with a minimum degree of 1 and a maximum
degree of n. It can be divided into n+1 disjoint subsets, the first of which contains the tree's root and the
other n subsets containing the tree's elements.

Trees have the following properties:


1. In a tree, there is only one path between each pair of vertices.
2. A graph G is a tree if each pair of vertices has only one path between them.
3. In a tree T with n vertices, there are n-1 edges.
4. If and only if a graph is minimally connected, it is a tree.

Tree terminologies:
Root: node without parent.

Siblings: node share the same parent.

Internal node: Node of at least one child is referred to as an internal node.

External node: (leaf) node without children.

Ancestors: parent, grandparent etc.

Depth of node: number of ancestors.

Height of node: maximum depth of any node.

Degree of nodes: the number of its children.

Degree of the tree: The maximum number of its node.


History of AVL TREE:
GM Adelson - Velsky and EM Landis developed the AVL Tree in 1962. The tree was given the name AVL
in honour of its creators.

Definition:
The AVL Tree is a height balanced binary search tree in which each node has a balance factor that is
determined by subtracting the height of the right sub-tree from the height of the left sub-tree. If the
equilibrium factor of each node is between -1 and 1, the tree is said to be balanced; otherwise, the tree
is unbalanced and must be balanced.

Balance Factor (k) = height (left(k)) - height (right(k))


The left sub-tree is one rank higher than the right sub-tree if the balancing factor of any node is 1. If
a node's equilibrium factor is 0, it implies that the left and right subtrees have the same height. If a
node's equilibrium factor is -1, it means the left sub-tree is one step below the right sub-tree.

The following diagram depicts an AVL tree. We can see that the equilibrium factor for each node is
somewhere between -1 and +1.

A self-balancing Binary search tree is the AVL tree. On both nodes, the disparity between the
heights of the left and right subtrees cannot exceed one.

Example:

Why AVL Tree:


The majority of BST operations (such as search, max, min, insert, remove, and so on) take 0(h) time,
where h is the BTS height. For a warped Binary tree, the cost of these operations can become 0(n). We
can guarantee an upper bond of o(logn) for all of these operations if we ensure that the tree's height
stays 0(logn) after each insertion and deletion.
Relation Between Binary and AVL tree:
For efficient data entry, a binary search tree is commonly used. However, in a few cases, such as a
connected list of subtrees with nodes in a chain, a binary search tree degenerates with most of the n
elements descending, and the tree's search efficiency becomes the o. (n). To deal with this, you can use
a full binary tree.

 A complete binary tree is said to be balanced if nodes are evenly divided between the
two subtrees of any given node.
 As a result, it is possible to assume that, in theory, all forms of binary search tree id full
tree id, but this is not possible for random data.
 Three physicists, Adelson, Velskii, and Landis, proposed and proved the principle of
node height balance and developed the algorithm to reorder and preserve the height
balance to solve the issue of random data.
 As a result, an AVL tree is a binary search tree with this definition. The binary search
tree's corresponding AVL tree is seen in the diagram below.

Properties:
 There is a root node in any tree (at the top).
 There are 0, one, or two child nodes in the root node.
 There are 0, one, or two child nodes in each child node, and so on.
 Each node has up to two offspring, with the left descendants being less than the current node
and the right descendants being less than the current node.
 The AVL tree algorithm is used to make changes to the tree, such as adding and removing items,
in order to keep it balanced.
 The AVL tree algorithm is used to find, integrate, and delete tree elements.
 The AVL tree algorithm is used to measure the tree's equilibrium property, which necessitates
tracking the balance factor, detecting imbalance, and restoring balance.
• The AVL algorithm uses a rotation strategy to keep the unbalanced subtree's nodes balanced.
• The AVL tree algorithm aids the depth first search algorithm in determining the depth of a
graph.
Balance factor:
The AVL tree is a binary search tree with a height balance. That is to say, an AVL tree is a binary
search tree that is also balanced. If the height difference between the left and right subtrees of a
node in the tree is either -1, 0 or +1, the binary tree is said to be balanced. To put it another
way, a binary tree is said to be balanced if the heights of each node's left and right children
differ by -1, 0 or +1. Any node in an AVL tree stores additional information known as the balance
element.

The disparity between the heights of a node's left and right subtrees is its balance factor. A node's
balancing factor is measured as the height of the left subtree minus the height of the right subtree (OR)
the height of the right subtree minus the height of the left subtree.

The left subtree of C in the second tree has a height of 2 and the right subtree has a height of 0, so the
disparity is 2. The right subtree of A has height 2 in the third tree, but the left is absent, so it is 0, and the
discrepancy is 2. Just one difference (balance factor) is allowed in the AVL tree.

Balance Factor = height(left-subtree) − height(right-subtree)


If the difference in the height of left and right sub-trees is more than 1, the tree is balanced using
some rotation techniques.

Applications:
1. AVL trees are useful when you're building a database where insertions and deletions aren't common
so you need to look up objects constantly.

2. AVL trees are mainly used for sorting sets and dictionaries in memory.

3. It is found in software other than database applications that need better searching
Advantages:
 AVL tree has the capability of performing the searching, insertion and deletion in more efficient
manner when its compare with BTS.
 Secondly it’s self-balancing capabilities.

Disadvantages:
 Major disadvantage with AVL tree is that even in the case of the tree slightly unbalance, it can impact
the time taken to perform insertion and deletion.
 It was discovered that AVL tree does not allow anything beyond the range -1 to 1.

References:
https://www.tutorialspoint.com/data_structures_algorithms/avl_tree_algorithm.htm#:~:tex
t=Named%20after%20their%20inventor%20Adelson,is%20called%20the%20Balance
%20Factor.
https://www.softwaretestinghelp.com/avl-trees-and-heap-data-structure-in-cpp/
http://www.btechsmartclass.com/data_structures/avl-trees.html
https://www.tutorialspoint.com/data_structures_algorithms/binary_search_tree.htm\

You might also like