Skip to content

Bilodev/AVL-Tree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages