Skip to content

Binary Search Tree in Javascript. A simple binary search tree data structure implementation in Javascript.

License

Notifications You must be signed in to change notification settings

techhysahil/BinarySearchTree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Binary Search Tree in Javascript. A simple binary search tree data structure implementation in Javascript.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published