Class: BST

BST()

BST Class Binary Search Tree

Constructor

new BST()

BST Constructor
Source:

Members

isEmpty

Indicates if the BST is empty
Source:

max

Returns max element in the BST
Source:

min

Returns min element in the BST
Source:

size

Returns number of element in the BST
Source:

Methods

add(key, valueopt) → {boolean}

Insert a new element in the BST
Parameters:
Name Type Attributes Default Description
key number Unique key for the element
value any <optional>
null Value of the element, null if not provided
Source:
Throws:
- If Element already exists in the BST
Type
Error
Returns:
- True - If element was added
Type
boolean

clear()

Clears the BST
Source:

get(keyopt) → {TreeElement}

Returns an existing element in the BST
Parameters:
Name Type Attributes Default Description
key number <optional>
null Unique key for the element, if null, return root of BST
Source:
Throws:
- If element is not found
Type
Error
Returns:
- Requested element, root of key is not provided
Type
TreeElement

has(key) → {boolean}

Indicates if an element exists in the BST
Parameters:
Name Type Description
key number Unique key for the element
Source:
Returns:
- True if element exists, false if element does not exists
Type
boolean

remove(key, typeopt) → {boolean}

Removes an existing element in the BST
Parameters:
Name Type Attributes Default Description
key number Unique key for the element
type string <optional>
predecessor Specifies delete type, allows 'predecessor' (default) for in-order predecessor, and 'successor' for in-order successor
Source:
Throws:
- If delete type is invalid
Type
Error
Returns:
- True - If element was added; False if element does not exists
Type
boolean

toArray(key, traversalopt) → {Array.<number>}

Returns an array containing the key of the elements in the BST
Parameters:
Name Type Attributes Default Description
key number Unique key for the element
traversal string <optional>
"in-order" Specifies Traversal type, allows 'in-order' (default), 'pre-order', 'post-order', and 'reverse-in-order
Source:
Returns:
- Array of element keys
Type
Array.<number>

update(key, valueopt) → {boolean}

Updates an existing element in the BST
Parameters:
Name Type Attributes Default Description
key number Unique key for the element
value any <optional>
null Value of the element, null if not provided
Source:
Throws:
- If element is not found
Type
Error
Returns:
- True - If element was edited
Type
boolean