Constructor
new BST(root)
Represents a BST (Binary Search Tree)
Parameters:
Name | Type | Description |
---|---|---|
root |
Node | null | The root of the tree |
Methods
(static) BST.fromArray() → {BST}
Creates a tree from a single-key array
Returns:
The tree
- Type
- BST
(static) BST.fromObject() → {BST}
Creates a tree from an object
Returns:
The tree
- Type
- BST
ceil() → {string|null}
Gets the smallest key in the BST larger than or equal to 'key'
Returns:
The
- Type
- string | null
check() → {boolean}
Checks the consistency of the tree
Returns:
Whether the BST is consistent
- Type
- boolean
contains() → {boolean}
Checks whether the given key is in the tree
Returns:
True when the key exists, false otherwise
- Type
- boolean
delete() → {this}
Deletes a node given the key
Returns:
The current object (for chaining capabilities)
- Type
- this
deleteMax() → {this}
Deletes the far right node
Returns:
The current object (for chaining capabilities)
- Type
- this
deleteMin() → {this}
Deletes the far left node
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'
Returns:
The
- Type
- string | null
get() → {mixed}
Gets the node's value given the key
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)
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
Returns:
The array representation
- Type
- Array
isBST() → {boolean}
Checks whether the data structure satisfy symmetric order
Returns:
True if the rule is satisfied, false otherwise
- Type
- boolean
isEmpty() → {boolean}
Checks whether the tree is empty
Returns:
True if the BST is empty, false otherwise
- Type
- boolean
max() → {string}
Gets the key of the far right most node
Returns:
The key
- Type
- string
min() → {string}
Gets the key of the far left most node
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
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
Returns:
The array representation
- Type
- Array
put() → {this}
Inserts an node in the tree (maintaining the structure order)
Returns:
The current object (for chaining capabilities)
- Type
- this
rank() → {number}
Gets the rank of the given key
Returns:
The rank of the key
- Type
- number
rankConsistent() → {boolean}
Checks if the tree is rank consistent
Returns:
True if rank consistency is satisfied, false otherwise
- Type
- boolean
select() → {string}
Gets the key of rank 'k'
Returns:
The key of rank 'k'
- Type
- string
size() → {number}
Gets the number of nodes in the tree
Returns:
The number of nodes
- Type
- number
sum() → {number}
Returns the sum of the nodes value
Returns:
Sum of nodes value
- Type
- number