A Red-Black Tree Visualizer built with C++ and SDL2, designed to help users understand the structure and operations of Red-Black Trees through interactive visualization.
- Interactive Visualization: See the tree structure update dynamically as you perform insertions and deletions.
- Dynamic Balancing: Observe rotations and color changes that maintain the Red-Black Tree properties.
- Error Handling: Detect and handle edge cases like duplicate insertions or empty deletions gracefully.
- User-Friendly Interface: Designed for ease of use with a clean, intuitive UI.
- Multiple Tree Management: Save and switch between trees effortlessly using the save button.
- Clone the repository:
https://github.com/Priyansh6747/Red-Black-Tree-Visualizer
-
The program does not contain a prebuilt executable file, so you need to build it first (or use a released version in the future). To build it, open a terminal in the project directory and run:
mingw32-make -f MakeFile
-
To run the program, use the following command:
.\main.exe
Note: No released version is available yet.
-
Red-Black Tree Properties
The visualizer enforces the following Red-Black Tree rules:
- Each node is either Red or Black.
- The root is always Black.
- Red nodes cannot have Red children ("No double reds").
- Every path from a node to its descendant null nodes must have the same number of Black nodes (Black height).
-
Operations
-
Insertion:
- Adds a new node and dynamically updates the visualization.
- Recolors and rotates nodes as necessary to maintain Red-Black Tree properties.
-
Deletion:
- Removes a node and rebalances the tree to restore its properties.
-
Reset:
- Clears the current tree, allowing you to start fresh.
-
Save:
- Save the Current Tree: Save the current working tree, including its structure and operations.
- Display Tree Buttons: Create a button for each saved tree, labeled with the tree's root value, with the minimum root value displayed first (priority queue ordering).
- Load a Tree on Click: Load the clicked tree and make it the active tree in the visualizer.
-
Contributions are welcome to enhance the functionality and features of the Red-Black Tree Visualizer.
How to Contribute
- Fork the repository on GitHub.
- Create a new branch for your feature or bug fix.
- Write clear and concise commit messages.
- Submit a pull request with a detailed description of your changes.
Future Enhancements
If you'd like to contribute, here are some ideas for future features:
- Implement animations for rotations and recoloring during balancing.
- Extend UI with advanced features using libraries like Dear ImGui.
- Provide export/import functionality in formats like JSON.
- We’re open to suggestions and contributions that improve usability and learning outcomes.