Bilodev / AVL-Tree

AVL (self-balancing binary) trees implemented using Pygame

Repository from Github https://github.comBilodev/AVL-TreeRepository from Github https://github.comBilodev/AVL-Tree

AVL Tree Visualization with Pygame

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.

What Are AVL Trees?

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.

Visualization with Pygame

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.

๐Ÿ› ๏ธ Features

  • 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

๐Ÿš€ Getting Started

  • Python 3.x
  • Pygame
pip install pygame
python main.py

๐Ÿ“ธ Screenshots

Empty Tree

empty

Full Tree (random)

tree

Search for "628" Node

search

"54" Node Deletion

Before

del

After

del

About

AVL (self-balancing binary) trees implemented using Pygame

License:MIT License


Languages

Language:Python 100.0%