BinarySearchTree

BinarySearchTree

Binary search tree.

Constructor

new BinarySearchTree()

In computer science, binary search trees (BST), sometimes called ordered or sorted binary trees, are a particular type of container: data structures that store "items" (such as numbers, names etc.) in memory. Full wikipedia article at: https://en.wikipedia.org/wiki/Binary_search_tree
Source:
Example
const BST = require('dstructures').BinarySearchTree;
const myBST = new BST();

Methods

find(data) → {Boolean|Any}

Finds given value within the BinarySearchTree.
Source:
Parameters:
Name Type Description
data any Given data.
Returns:
Type:
Boolean | Any
Returns given value or false if the value is not present.
Example
BST.insert(10);
BST.insert(32);
BST.insert(41);
BST.find(32); // 32
BST.find(72); // false

inOrder() → {Array}

Returns sorted array representation of the BinarySearchTree.
Source:
Returns:
Type:
Array
Returns array representation of the BinarySearchTree.
Example
BST.insert(10);
BST.insert(32);
BST.insert(41);
BST.inOrder(41); // [10, 32, 41]

insert(data)

Inserts new node in a BinarySearchTree.
Source:
Parameters:
Name Type Description
data any Given data.
Example
BST.insert(10);

max() → {Any}

Returns the biggest value within the BinarySearchTree.
Source:
Returns:
Type:
Any
Returns the biggest value within the BinarySearchTree.
Example
BST.insert(10);
BST.insert(32);
BST.insert(41);
BST.max(); // 41

min() → {Any}

Returns the smallest value within the BinarySearchTree.
Source:
Returns:
Type:
Any
Returns the smallest value within the BinarySearchTree.
Example
BST.insert(10);
BST.insert(32);
BST.insert(41);
BST.min(); // 10

remove(data) → {Boolean|undefined}

Removes node from the BinarySearchTree.
Source:
Parameters:
Name Type Description
data any Given data.
Returns:
Type:
Boolean | undefined
Returns false if 'data' argument is ommited, or undefined if the 'data' argument value is not present within a BinarySearchTree.
Example
BST.insert(10);
BST.insert(32);
BST.insert(41);
BST.remove(41); // 10, 32