This project is a visualization of AVL trees implemented using Pygame. The goal is to provide an intuitive and interactive way to understand how AVL trees work — especially their self-balancing behavior during insertions and deletions.
An AVL tree is a type of self-balancing binary search tree. Named after its inventors Adelson-Velsky and Landis, it ensures that the height difference (balance factor) between the left and right subtrees of any node is at most 1. This balancing guarantees that the tree maintains O(log n) time complexity for search, insert, and delete operations.
To maintain this balance, AVL trees automatically perform rotations (left, right, or a combination) whenever an insertion or deletion causes an imbalance.
In this project, the AVL tree structure is not only implemented but also visually represented using Pygame. Each node is drawn on the screen with edges connecting parent and child nodes. As you insert or remove elements, you can watch the tree rebalance itself in real time.
- Insert nodes and watch the AVL rotations dynamically
- Node highlighting and balance factor visualization
- Clear graphical layout with automatically spaced nodes
- Revert changes made to the tree
- Genereate Random Tree
- Python 3.x
- Pygame
pip install pygame
python main.py