• 0

Create a binary search tree in javascript

Create a simple binary search tree data structure in javascript.

Binary tree :

It is a tree data structure in which each node has at most two children, which are referred to as the left child and the right child.

Binary search tree (a.k.a. ordered or sorted binary trees):

  • Binary search trees keep their keys in the sorted order so that lookup and other operations can use the principle of binary search.

  • On average, each comparison allows the operations to skip about half of the tree, so that each lookup, insertion or deletion takes time proportional to the logarithm of the number of items stored in the tree.

  • This is much better than the linear time required to find items by key in an (unsorted) array but slower than the corresponding operations on hash tables.

Binary-Search-Tree-in-post-min

This post is the pre-requisite for the following examples.

Solution :

This solution uses ES6 syntax.



This solution is if you are not familiar with ES6 syntax.