Skip to content

mahajialirezaei/RedBlackTree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Red-Black Tree Implementation

Overview

This project provides an implementation of a Red-Black Tree, a self-balancing binary search tree, written in Java. The Red-Black Tree ensures that the tree remains balanced, resulting in efficient operations for insertion, deletion, and search with a time complexity of O(log n).

Additionally, this implementation includes a JavaFX-based graphical visualization, allowing users to interact with the tree dynamically.

Features

  • Insertion of elements while maintaining the Red-Black Tree properties
  • Deletion of elements with automatic rebalancing
  • Searching for a specific element
  • Tree Traversals (in-order, pre-order, post-order)
  • Graphical Visualization using JavaFX for an interactive experience

Getting Started

Prerequisites

Ensure you have the following installed:

  • Java Development Kit (JDK 11 or later)
  • JavaFX SDK (included in newer JDKs or available separately)
  • An IDE such as IntelliJ IDEA, Eclipse, or NetBeans (recommended for JavaFX development)

Installation

  1. Clone the repository:
    git clone https://github.com/mahajialirezaei/RedBlackTree.git
  2. Open the project in your IDE.
  3. Ensure JavaFX libraries are correctly configured in the project settings.
  4. Compile and run the project:
    javac -d out --module-path <path-to-javafx-lib> --add-modules javafx.controls,javafx.fxml *.java
    java --module-path <path-to-javafx-lib> --add-modules javafx.controls,javafx.fxml -cp out Main
    (Replace <path-to-javafx-lib> with the actual JavaFX SDK path.)

Usage

Once the application is running, you can:

  • Insert elements by entering values in the graphical interface.
  • Delete elements from the tree dynamically.
  • Search for a specific element.
  • View the tree structure visually with dynamic updates.

Red-Black Tree Properties

The tree maintains the following properties:

  1. Every node is either red or black.
  2. The root node is always black.
  3. Red nodes cannot have red children (no two consecutive red nodes).
  4. Every path from a node to its descendant NULL nodes must have the same number of black nodes.

Example (Java Implementation)

RedBlackTree tree = new RedBlackTree();
tree.insert(10);
tree.insert(20);
tree.insert(30);
tree.insert(15);
tree.display();

This inserts elements into the tree while maintaining Red-Black properties and displays the tree structure.

Contributing

Contributions are welcome! Feel free to submit issues or pull requests to improve the implementation.

Author

Mahaji Alirezaei


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages