Détail du package

namastey-binary-search-tree

namasteyduniya52ISC1.0.0

A JavaScript package that implements a Binary Search Tree (BST) data structure with essential methods for efficient data storage and retrieval.

binary-search-tree, bst, data-structure, tree

readme

namastey-binary-search-tree

A JavaScript package implementing the Binary Search Tree (BST) data structure, along with various essential methods to manage and manipulate the tree.

Features

  • insert(value): Inserts a new node with the specified value into the BST.
  • findMin(): Returns the minimum value in the BST.
  • findMax(): Returns the maximum value in the BST.
  • search(value): Searches for a specific value in the BST and returns true if found, false otherwise.
  • inOrder(): Returns an array of values in in-order traversal (Left, Root, Right).
  • preOrder(): Returns an array of values in pre-order traversal (Root, Left, Right).
  • postOrder(): Returns an array of values in post-order traversal (Left, Right, Root).
  • remove(value): Removes the node with the specified value from the BST.

Installation

To install the package globally, use:

npm install -g namastey-binary-search-tree

Examples

const BinarySearchTree = require('namastey-binary-search-tree');

const bst = new BinarySearchTree();

bst.insert(15);
bst.insert(25);
bst.insert(10);
bst.insert(7);
bst.insert(22);
bst.insert(17);
bst.insert(13);
bst.insert(5);
bst.insert(9);
bst.insert(27);

console.log('In-order traversal:', bst.inOrder()); 
// Output: In-order traversal: [ 5, 7, 9, 10, 13, 15, 17, 22, 25, 27 ]

console.log('Pre-order traversal:', bst.preOrder()); 
// Output: Pre-order traversal: [ 15, 10, 7, 5, 9, 13, 25, 22, 17, 27 ]

console.log('Post-order traversal:', bst.postOrder()); 
// Output: Post-order traversal: [ 5, 9, 7, 13, 10, 17, 22, 27, 25, 15 ]