Introduction to AVL tree

ayabouchiha

Aya Bouchiha

Posted on July 1, 2021

Introduction to AVL  tree

Hello, today, we're going to talk about AVL tree.
#day_19

why we need to use AVL trees.

Sometimes, the Binary search tree's operations become O(n) instead of O(log n) due to being a skewed binary search tree, that's why Adelson, Velskii and Landis. so what's an AVL tree ?


if you're not familiar with binary search tree, this post will help you :)

Definition of AVL tree

AVL tree is a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees cannot be more than one for all nodes.

Time and Space complexity

The space complexity of the avl tree is O(n)

insert search delete
O(log n) O(log n) O(log n)

Balance factor

the difference between the height of left and right subtrees can be calculated using this formula below:

BalanceFactor = height(left-sutree) − height(right-sutree)
Enter fullscreen mode Exit fullscreen mode

if the balance factor was 1 or 0 or -1, the tree is balanced, if not, we use the rotation to make it balanced. There are four types of rotation:

  1. Right rotation
  2. Left rotation
  3. Right-Left rotation
  4. Left-Right rotation

in the next post, we'll cover rotation types with the implementation, see you tomorrow, have a great day!

References and useful resources

💖 💪 🙅 🚩
ayabouchiha
Aya Bouchiha

Posted on July 1, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Depth First Search (DFS) Algorithm
algorithms Depth First Search (DFS) Algorithm

July 10, 2021

Breadth First Search (BFS) Algorithm
algorithms Breadth First Search (BFS) Algorithm

July 9, 2021

Introduction to AVL  tree
algorithms Introduction to AVL tree

July 1, 2021

deletion in binary search tree
algorithms deletion in binary search tree

June 29, 2021