Class: BST

j. BST

Constructor

new BST(root)

Represents a BST (Binary Search Tree)
Parameters:
Name Type Description
root Node | null The root of the tree
Source:

Methods

(static) BST.fromArray() → {BST}

Creates a tree from a single-key array
Source:
Returns:
The tree
Type
BST

(static) BST.fromObject() → {BST}

Creates a tree from an object
Source:
Returns:
The tree
Type
BST

ceil() → {string|null}

Gets the smallest key in the BST larger than or equal to 'key'
Source:
Returns:
The
Type
string | null

check() → {boolean}

Checks the consistency of the tree
Source:
Returns:
Whether the BST is consistent
Type
boolean

contains() → {boolean}

Checks whether the given key is in the tree
Source:
Returns:
True when the key exists, false otherwise
Type
boolean

delete() → {this}

Deletes a node given the key
Source:
Returns:
The current object (for chaining capabilities)
Type
this

deleteMax() → {this}

Deletes the far right node
Source:
Returns:
The current object (for chaining capabilities)
Type
this

deleteMin() → {this}

Deletes the far left node
Source:
Returns:
The current object (for chaining capabilities)
Type
this

floor() → {string|null}

Gets the largest key in the BST less than or equal to 'key'
Source:
Returns:
The
Type
string | null

get() → {mixed}

Gets the node's value given the key
Source:
Returns:
The found value (null if not)
Type
mixed

height() → {number}

Gets the height of the tree (i.e. the height of the root node)
Source:
Returns:
The height of the tree
Type
number

inOrder() → {Array}

Gets an array (linear) representation of the BST visiting the left subtree first, then the current node and then the right subtree
Source:
Returns:
The array representation
Type
Array

isBST() → {boolean}

Checks whether the data structure satisfy symmetric order
Source:
Returns:
True if the rule is satisfied, false otherwise
Type
boolean

isEmpty() → {boolean}

Checks whether the tree is empty
Source:
Returns:
True if the BST is empty, false otherwise
Type
boolean

max() → {string}

Gets the key of the far right most node
Source:
Returns:
The key
Type
string

min() → {string}

Gets the key of the far left most node
Source:
Returns:
The key
Type
string

postOrder() → {Array}

Gets an array (linear) representation of the BST visiting the left subtree first, then the right subtree and then the current node
Source:
Returns:
The array representation
Type
Array

preOrder() → {Array}

Gets an array (linear) representation of the BST visiting the current node first, then the left and the right subtrees
Source:
Returns:
The array representation
Type
Array

put() → {this}

Inserts an node in the tree (maintaining the structure order)
Source:
Returns:
The current object (for chaining capabilities)
Type
this

rank() → {number}

Gets the rank of the given key
Source:
Returns:
The rank of the key
Type
number

rankConsistent() → {boolean}

Checks if the tree is rank consistent
Source:
Returns:
True if rank consistency is satisfied, false otherwise
Type
boolean

select() → {string}

Gets the key of rank 'k'
Source:
Returns:
The key of rank 'k'
Type
string

size() → {number}

Gets the number of nodes in the tree
Source:
Returns:
The number of nodes
Type
number

sum() → {number}

Returns the sum of the nodes value
Source:
Returns:
Sum of nodes value
Type
number