Binary Search Tree in Javascript. A simple binary search tree data structure implementation in Javascript.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
BSTVisual
dist
.gitignore
BST.js
Gruntfile.js
LICENCE.md
README.md
bower.json
package.json

README.md

BST : BinarySearchTree

BST.js is a Javascript library for Binary Search Tree. A simple binary search tree data structure implementation in Javascript. This implementation does not allow duplicate values to be inserted into the tree, ensuring that there is just one instance of each value.

Live BST Visualizer : Click Here

Installing

Using NPM:

npm install Binary-search-tree

Using Bower:

bower install Binary-search-tree

Getting Started

BST js contains the following functions:

  • add
  • contains
  • minValue
  • removeTree
  • traversalTree
  • size
  • toArray
  • toString
  • maxDepth
  • remove etc.

Let's see how it's actually works:

JavaScript (Client Side):

var binarySearchTree = new BST();	//initlize binary tree

Node JS (Server Side):

var bst = require('./BST.js');
var binarySearchTree = new bst.BST()	//initlize binary tree

Function Usage

//Adding a node 
binarySearchTree.add(23);
binarySearchTree.add(89);

//search an element
binarySearchTree.contains(89);

//Remove an element
binarySearchTree.remove(89);

//Traversing an binary search tree
binarySearchTree.traversalTree({type:'inorder'},callback); //For inorder traversal
binarySearchTree.traversalTree({type:'preorder'},callback); //For preorder traversal
binarySearchTree.traversalTree({type:'postorder'},callback); //For postorder traversal

//maximum depth of Binary search tree
binarySearchTree.maxDepth();

//Return binary search tree elements in array
binarySearchTree.toArray();

//Return binary search tree elements in string form
binarySearchTree.toString();

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments