KEMBAR78
AVL tree ( Balanced Binary Search Tree)-Data Structure | PDF
AVL Tree
ID no:-170413107013
Name:-Yaksh Jethva
Content
➔ About AVL Tree
➔ Operation Performed on AVL Tree
◆ Searching
◆ Traverse
◆ Insertion
◆ Deletion
➔ AVL Rotation
◆ Left Rotation
◆ Right Rotation
◆ Left-Right Rotation
◆ Right-Left Rotation
About AVL tree
➢ An AVL tree is a self-balancing binary search tree. It was the first
such data structure to be invented. In an AVL tree, the heights of
the two child subtrees of any node differ by at most one; if at any
time they differ by more than one, rebalancing is done to restore
this property.
➢ The AVL tree is named after its two Soviet inventors, Georgy
Adelson-Velsky and Evgenii Landis, who published it in their 1962
paper "An algorithm for the organization of information".
Operations
Searching
Searching for a specific key in an AVL tree can be done the same way as
that of a normal unbalanced binary search tree. The number of
comparisons required for successful search is limited by the height h and
for unsuccessful search is very close to h, so both are in O(log n).
Traversal
Traversal term refers to the process of visiting (checking and/or
updating) each node in a tree data structure exactly once.
Operation
Insertion
When inserting an element into an AVL tree, you initially follow the same process as
inserting into a Binary Search Tree. More explicitly: In case a preceding search has
not been successful the search routine returns the tree itself with indication
EMPTY and the new node is inserted as root. Or, if the tree has not been empty the
search routine returns a node and a direction (left or right) where the returned
node does not have a child. Then the node to be inserted is made child of the
returned node at the returned direction.
Deletion
The preliminary steps for deleting a node are described in section Binary search
tree. There, the effective deletion of the subject node or the replacement node
decreases the height of the corresponding child tree either from 1 to 0 or from 2
to 1, if that node had a child.
Right Rotation
AVL tree may become unbalanced, if a node is inserted in the left subtree of the
left subtree. The tree then needs a right rotation.
As depicted, the unbalanced node becomes the right child of its left child by
performing a right rotation.
AVL Rotation
To balance itself, an AVL tree may perform the following four kinds of
rotations −
● Left rotation
● Right rotation
● Left-Right rotation
● Right-Left rotation
The first two rotations are single rotations and the next two rotations are
double rotations. To have an unbalanced tree, we at least need a tree of
height 2. With this simple tree, let's understand them one by one.
Left Rotation
If a tree becomes unbalanced, when a node is inserted into the right subtree of
the right subtree, then we perform a single left rotation −
In our example, node A has become unbalanced as a node is inserted in the right
subtree of A's right subtree. We perform the left rotation by making A the
left-subtree of B.
Left-Right Rotation
Double rotations are slightly complex version of already explained versions of rotations. To
understand them better, we should take note of each action performed while rotation. Let's first
check how to perform Left-Right rotation. A left-right rotation is a combination of left rotation
followed by right rotation.
Right-Left Rotation
The second type of double rotation is Right-Left Rotation. It is a combination of
right rotation followed by left rotation.
Thank YOu!!!

AVL tree ( Balanced Binary Search Tree)-Data Structure

  • 1.
  • 2.
    Content ➔ About AVLTree ➔ Operation Performed on AVL Tree ◆ Searching ◆ Traverse ◆ Insertion ◆ Deletion ➔ AVL Rotation ◆ Left Rotation ◆ Right Rotation ◆ Left-Right Rotation ◆ Right-Left Rotation
  • 3.
    About AVL tree ➢An AVL tree is a self-balancing binary search tree. It was the first such data structure to be invented. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they differ by more than one, rebalancing is done to restore this property. ➢ The AVL tree is named after its two Soviet inventors, Georgy Adelson-Velsky and Evgenii Landis, who published it in their 1962 paper "An algorithm for the organization of information".
  • 4.
    Operations Searching Searching for aspecific key in an AVL tree can be done the same way as that of a normal unbalanced binary search tree. The number of comparisons required for successful search is limited by the height h and for unsuccessful search is very close to h, so both are in O(log n). Traversal Traversal term refers to the process of visiting (checking and/or updating) each node in a tree data structure exactly once.
  • 5.
    Operation Insertion When inserting anelement into an AVL tree, you initially follow the same process as inserting into a Binary Search Tree. More explicitly: In case a preceding search has not been successful the search routine returns the tree itself with indication EMPTY and the new node is inserted as root. Or, if the tree has not been empty the search routine returns a node and a direction (left or right) where the returned node does not have a child. Then the node to be inserted is made child of the returned node at the returned direction. Deletion The preliminary steps for deleting a node are described in section Binary search tree. There, the effective deletion of the subject node or the replacement node decreases the height of the corresponding child tree either from 1 to 0 or from 2 to 1, if that node had a child.
  • 6.
    Right Rotation AVL treemay become unbalanced, if a node is inserted in the left subtree of the left subtree. The tree then needs a right rotation. As depicted, the unbalanced node becomes the right child of its left child by performing a right rotation.
  • 7.
    AVL Rotation To balanceitself, an AVL tree may perform the following four kinds of rotations − ● Left rotation ● Right rotation ● Left-Right rotation ● Right-Left rotation The first two rotations are single rotations and the next two rotations are double rotations. To have an unbalanced tree, we at least need a tree of height 2. With this simple tree, let's understand them one by one.
  • 8.
    Left Rotation If atree becomes unbalanced, when a node is inserted into the right subtree of the right subtree, then we perform a single left rotation − In our example, node A has become unbalanced as a node is inserted in the right subtree of A's right subtree. We perform the left rotation by making A the left-subtree of B.
  • 9.
    Left-Right Rotation Double rotationsare slightly complex version of already explained versions of rotations. To understand them better, we should take note of each action performed while rotation. Let's first check how to perform Left-Right rotation. A left-right rotation is a combination of left rotation followed by right rotation.
  • 10.
    Right-Left Rotation The secondtype of double rotation is Right-Left Rotation. It is a combination of right rotation followed by left rotation.
  • 11.