Professional Documents
Culture Documents
General Tree
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.
Tree terminologies:
Root: node without parent.
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.
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:
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.
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\