namastey-red-black-tree
v1.0.0
Published
A JavaScript package implementing the Red-Black Tree data structure for efficient data management.
Downloads
3
Maintainers
Readme
namastey-red-black-tree
Brief Description
The namastey-red-black-tree
package provides a JavaScript implementation of the Red-Black Tree data structure, offering efficient operations for insertion, deletion, and searching within a self-balancing binary search tree.
Features
- insert(value): Inserts a new value into the Red-Black Tree while maintaining balance.
- searchTree(value): Searches for a specific value within the tree and returns the node if found.
- inOrderTraversal(): Traverses the tree in order and prints the values in ascending order.
- rotateLeft(node): Performs a left rotation around the given node.
- rotateRight(node): Performs a right rotation around the given node.
- fixInsert(node): Ensures the tree remains balanced after an insertion.
Installation
To install the namastey-red-black-tree
package globally, use the following command:
npm install -g namastey-red-black-tree
Examples
const RedBlackTree = require('namastey-red-black-tree');
const rbTree = new RedBlackTree();
rbTree.insert(10);
rbTree.insert(20);
rbTree.insert(15);
console.log("In-order traversal:");
rbTree.inOrderTraversal(); // Output: 10, 15, 20
const foundNode = rbTree.searchTree(15);
console.log(foundNode ? `Found: ${foundNode.value}` : "Not Found"); // Output: Found: 15