Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • DSA
  • Interview Problems on Tree
  • Practice Tree
  • MCQs on Tree
  • Tutorial on Tree
  • Types of Trees
  • Basic operations
  • Tree Traversal
  • Binary Tree
  • Complete Binary Tree
  • Ternary Tree
  • Binary Search Tree
  • Red-Black Tree
  • AVL Tree
  • Full Binary Tree
  • B-Tree
  • Advantages & Disadvantages
Open In App
Next Article:
What is AVL Tree | AVL Tree meaning
Next article icon

AVL Tree Data Structure

Last Updated : 19 Jun, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

An AVL tree defined as a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees for any node cannot be more than one.

Balance Factor = left subtree height - right subtree height
For a Balanced Tree(for every node): -1 ≤ Balance Factor ≤ 1

Example of an AVL Tree:

The balance factors for different nodes are: 12 : +1, 8 : +1, 18 : +1, 5 : +1, 11 : 0, 17 : 0 and 4 : 0. Since all differences are lies between -1 to +1, so the tree is an AVL tree.

Example-of-an-AVL-Tree-11


Example of a BST which is not an AVL Tree:

The Below Tree is not an AVL Tree as the balance factor for nodes 8, 4 and 7 is more than 1.

Example-of-an-AVL-Tree-22


Important Points about AVL Tree:

  • Balance Factor Range:
    • The balance factor of a node in an AVL Tree is defined as: Balance Factor = height(left subtree) - height(right subtree)
    • For AVL Trees, the balance factor must always be -1, 0, or +1.
    • If a node’s balance factor becomes less than -1 or greater than +1 after an operation, rebalancing is required.
  • Rotations:
    • AVL Trees use four types of rotations to rebalance themselves after insertions and deletions:
      • Left-Left (LL) Rotation
      • Right-Right (RR) Rotation
      • Left-Right (LR) Rotation
      • Right-Left (RL) Rotation
    • These rotations are designed to restore balance in O(1) time while ensuring the overall time complexity remains O(log n).
  • Insertion and Deletion:
    • While insertion is followed by upward traversals to check balance and apply rotations, deletion can be more complex due to multiple rotations possibly being required.
    • AVL Trees may require multiple rebalancing steps during deletion, unlike Red-Black Trees which limit this better.
  • Use Cases:
    • AVL Trees are particularly useful when you need frequent and efficient lookups, like in database indexing, memory-intensive applications, or where predictable time complexity is crucial.
  • Drawbacks Compared to Other Trees:
    • Although faster in lookups than Red-Black Trees, AVL Trees might incur slightly more overhead on insertions and deletions due to stricter balancing requirements.
    • As a result, Red-Black Trees are more common in standard libraries like TreeMap or TreeSet in Java or map in C++ STL.
  • In-order Traversal:
    • An in-order traversal of an AVL Tree still gives you elements in sorted order, just like any Binary Search Tree.

Operations on an AVL Tree:

  • Searching : It is same as normal Binary Search Tree (BST) as an AVL Tree is always a BST. So we can use the same implementation as BST. The advantage here is time complexity is O(log n)
  • Insertion : It does rotations along with normal BST insertion to make sure that the balance factor of the impacted nodes is less than or equal to 1 after insertion
  • Deletion : It also does rotations along with normal BST deletion to make sure that the balance factor of the impacted nodes is less than or equal to 1 after deletion.

Please refer Insertion in AVL Tree and Deletion in AVL Tree for details.

Rotating the subtrees (Used in Insertion and Deletion)

An AVL tree may rotate in one of the following four ways to keep itself balanced while making sure that the BST properties are maintained.

1. Left-Left Rotation:

  • Occurs when a node is inserted into the right subtree of the right child, causing the balance factor to become less than -1.
  • Fix: Perform a single left rotation.



2. Right-Right Rotation:

  • Occurs when a node is inserted into the left subtree of the left child, making the balance factor greater than +1.
  • Fix: Perform a single right rotation.

3. Left-Right Rotation:

  • Occurs when a node is inserted into the right subtree of the left child, which disturbs the balance factor of an ancestor node, making it left-heavy.
  • Fix: Perform a left rotation on the left child, followed by a right rotation on the node.


4. Right-Left Rotation:

  • Occurs when a node is inserted into the left subtree of the right child, which disturbs the balance factor of an ancestor node, making it right-heavy.
  • Fix: Perform a right rotation on the right child, followed by a left rotation on the node.


Applications of AVL Tree:

  1. AVL Tree is used as a first example self balancing BST in teaching DSA as it is easier to understand and implement compared to Red Black
  2. Applications, where insertions and deletions are less common but frequent data lookups along with other operations of BST like sorted traversal, floor, ceil, min and max.
  3. Red Black tree is more commonly implemented in language libraries like map in C++, set in C++, TreeMap in Java and TreeSet in Java.
  4. AVL Trees can be used in a real time environment where predictable and consistent performance is required.

Advantages of AVL Tree:

  1. AVL trees can self-balance themselves and therefore provides time complexity as O(log n) for search, insert and delete.
  2. As it is a balanced BST, so items can be traversed in sorted order.
  3. Since the balancing rules are strict compared to Red Black Tree, AVL trees in general have relatively less height and hence the search is faster.
  4. AVL tree is relatively less complex to understand and implement compared to Red Black Trees.

Disadvantages of AVL Tree:

  1. It is difficult to implement compared to normal BST.
  2. Less used compared to Red-Black trees. Due to its rather strict balance.
  3. AVL trees provide complicated insertion and removal operations as more rotations are performed.

Related Articles:

  • Insertion in an AVL Tree
  • Deletion in an AVL Tree
  • Red Black Tree

Next Article
What is AVL Tree | AVL Tree meaning

A

akashjha2671
Improve
Article Tags :
  • Tree
  • Technical Scripter
  • DSA
  • Technical Scripter 2022
  • AVL-Tree
Practice Tags :
  • AVL-Tree
  • Tree

Similar Reads

    AVL Tree Data Structure
    An AVL tree defined as a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees for any node cannot be more than one. Balance Factor = left subtree height - right subtree heightFor a Balanced Tree(for every node): -1 ≤ Balance Factor ≤ 1Example of an
    5 min read
    What is AVL Tree | AVL Tree meaning
    An AVL is a self-balancing Binary Search Tree (BST) where the difference between the heights of left and right subtrees of any node cannot be more than one. KEY POINTSIt is height balanced treeIt is a binary search treeIt is a binary tree in which the height difference between the left subtree and r
    2 min read
    Insertion in an 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. Insertion in an AVL Tree follows the same basic rules as in a Binary Search Tree (BST):A new key is placed in its correct position based on BST
    15+ min read
    Insertion, Searching and Deletion in AVL trees containing a parent node pointer
    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. The insertion and deletion in AVL trees have been discussed in the previous article. In this article, insert, search, and delete operations are
    15+ min read
    Deletion in an AVL Tree
    We have discussed Insertion of AVL Tree. In this post, we will follow a similar approach for deletion.Steps to follow for deletion. To make sure that the given tree remains AVL after every deletion, we must augment the standard BST delete operation to perform some re-balancing. Following are two bas
    15+ min read
    How is an AVL tree different from a B-tree?
    AVL Trees: AVL tree is a self-balancing binary search tree in which each node maintain an extra factor which is called balance factor whose value is either -1, 0 or 1. B-Tree: A B-tree is a self - balancing tree data structure that keeps data sorted and allows searches, insertions, and deletions in
    1 min read
    Practice questions on Height balanced/AVL Tree
    AVL tree is binary search tree with additional property that difference between height of left sub-tree and right sub-tree of any node can’t be more than 1. Here are some key points about AVL trees:If there are n nodes in AVL tree, minimum height of AVL tree is floor(log 2 n). If there are n nodes i
    4 min read
    AVL with duplicate keys
    Please refer below post before reading about AVL tree handling of duplicates. How to handle duplicates in Binary Search Tree?This is to augment AVL tree node to store count together with regular fields like key, left and right pointers. Insertion of keys 12, 10, 20, 9, 11, 10, 12, 12 in an empty Bin
    15+ min read
    Count greater nodes in AVL tree
    In this article we will see that how to calculate number of elements which are greater than given value in AVL tree. Examples: Input : x = 5 Root of below AVL tree 9 / \ 1 10 / \ \ 0 5 11 / / \ -1 2 6 Output : 4 Explanation: there are 4 values which are greater than 5 in AVL tree which are 6, 9, 10
    15+ min read
    Difference between Binary Search Tree and AVL Tree
    Binary Search Tree:A binary Search Tree is a node-based binary tree data structure that has the following properties: The left subtree of a node contains only nodes with keys lesser than the node’s key.The right subtree of a node contains only nodes with keys greater than the node’s key.The left and
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences