namastey-binary-tree
namastey-binary-tree is a JavaScript package that implements the Binary Tree data structure along with various important methods such as insertion, traversal (in-order, pre-order, post-order), finding minimum and maximum values, and searching for a value.
Features
- insert(value): Inserts a new node into the Binary Tree.
- inOrder(): Performs an in-order traversal of the Binary Tree and returns the result as an array.
- preOrder(): Performs a pre-order traversal of the Binary Tree and returns the result as an array.
- postOrder(): Performs a post-order traversal of the Binary Tree and returns the result as an array.
- findMin(): Finds and returns the minimum value in the Binary Tree.
- findMax(): Finds and returns the maximum value in the Binary Tree.
- search(value): Searches for a value in the Binary Tree and returns
true
if found, otherwise false
.
Installation
To install the package globally, use the following command:
npm install -g namastey-binary-tree
Examples
const BinaryTree = require('namastey-binary-tree');
const tree = new BinaryTree();
tree.insert(50);
tree.insert(30);
tree.insert(70);
tree.insert(20);
tree.insert(40);
tree.insert(60);
tree.insert(80);
console.log('In-order Traversal:', tree.inOrder());
console.log('Minimum Value:', tree.findMin());
console.log('Maximum Value:', tree.findMax());
console.log('Search for 60:', tree.search(60));
console.log('Search for 25:', tree.search(25));