This project provides a graphical user interface (GUI) for visualizing the operations of an AVL tree, a self-balancing binary search tree. The AVL tree ensures that the tree remains balanced after insertions by performing necessary rotations. The GUI allows users to observe the step-by-step insertion process, including the balancing rotations, and displays the tree structure along with traversal results.
- Interactive Visualization: Visualize the AVL tree structure with nodes, edges, and balance factors.
- Step-by-Step Insertion: Observe the insertion process with animations for rotations.
- Traversal Results: Display pre-order, in-order, and post-order traversal results.
- Animation Control: Adjust the animation speed (Slow, Normal, Fast).
- Restart Functionality: Restart the insertion process with a single button click.
- Detailed Logging: View detailed steps of the insertion process, including rotations performed.
-
Clone the Repository:
git clone https://github.com/durgenious/avl-tree-visualization.git cd avl-tree-visualization -
Compile and Run:
- Ensure you have Java installed.
- Compile the Java files:
javac *.java - Run the
AVLTreeDemoclass:java AVLTreeDemo
-
Using the GUI:
- The GUI will open, displaying an empty AVL tree.
- The insertion process will start automatically, inserting keys one by one.
- Observe the tree structure, balance factors, and traversal results in the GUI.
- Use the speed control to adjust the animation speed.
- Click the "Restart" button to reset the tree and start the insertion process again.
- AVLNode.java: Represents a node in the AVL tree.
- AVLTreeInterface.java: Defines the interface for the AVL tree operations.
- AVLTree.java: Implements the AVL tree, including insertion, balancing, and traversal methods.
- AVLTreeVisualizer.java: Provides the GUI for visualizing the AVL tree.
- AVLTreeDemo.java: The main class to run the AVL tree visualization.
Here is an example of how the AVL tree is visualized:
- Initial State: The tree is empty.
- Insertion: Keys are inserted one by one, and the tree is balanced after each insertion.
- Rotations: If a rotation is needed to balance the tree, the GUI will animate the rotation.
- Final State: After all keys are inserted, the final tree structure and traversal results are displayed.
You can customize the keys to be inserted by modifying the keys array in the AVLTreeDemo class:
int[] keys = {12, 22, 91, 13, 16, 14, 15, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, 28, 29, 30};Uncomment alternative arrays or create your own to visualize different sets of keys.
- Java Development Kit (JDK) 8 or higher.
- No external libraries are required.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please fork the repository and submit a pull request with your changes.
- This project was inspired by the need to visually understand AVL tree operations.
- Special thanks to the Java Swing library for providing the tools to create the GUI.
For any questions or suggestions, please contact [email protected].
Enjoy visualizing AVL trees with this interactive tool!
