Class AVLTree<K, V, R, NODE, TREE>

  1. Height-Balanced: Each node's left and right subtrees differ in height by no more than one.
  2. Automatic Rebalancing: AVL trees rebalance themselves automatically during insertions and deletions.
  3. Rotations for Balancing: Utilizes rotations (single or double) to maintain balance after updates.
  4. Order Preservation: Maintains the binary search tree property where left child values are less than the parent, and right child values are greater.
  5. Efficient Lookups: Offers O(log n) search time, where 'n' is the number of nodes, due to its balanced nature.
  6. Complex Insertions and Deletions: Due to rebalancing, these operations are more complex than in a regular BST.
  7. Path Length: The path length from the root to any leaf is longer compared to an unbalanced BST, but shorter than a linear chain of nodes.

Type Parameters

  • K = any

  • V = any

  • R = BTNEntry<K, V>

  • NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>

  • TREE extends AVLTree<K, V, R, NODE, TREE> = AVLTree<K, V, R, NODE, AVLTreeNested<K, V, R, NODE>>

Hierarchy

Implements

  • IBinaryTree<K, V, R, NODE, TREE>

Constructors

  • This is a constructor function for an AVLTree class that initializes the tree with keys, nodes, entries, or raw elements.

    Type Parameters

    • K = any

    • V = any

    • R = BTNEntry<K, V>

    • NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>

    • TREE extends AVLTree<K, V, R, NODE, TREE> = AVLTree<K, V, R, NODE, AVLTreeNested<K, V, R, NODE>>

    Parameters

    • keysOrNodesOrEntriesOrRawElements: Iterable<R | KeyOrNodeOrEntry<K, V, NODE>> = []

      The keysOrNodesOrEntriesOrRawElements parameter is an iterable object that can contain either keys, nodes, entries, or raw elements. These elements will be used to initialize the AVLTree.

    • Optional options: AVLTreeOptions<K, V, R>

      The options parameter is an optional object that can be used to customize the behavior of the AVLTree. It can include properties such as compareFn (a function used to compare keys), allowDuplicates (a boolean indicating whether duplicate keys are allowed), and nodeBuilder (

    Returns AVLTree<K, V, R, NODE, TREE>

Accessors

  • get NIL(): NODE
  • The function returns the value of the _NIL property.

    Returns NODE

    The method is returning the value of the _NIL property.

  • get comparator(): Comparator<K>
  • The function returns the value of the _comparator property.

    Returns Comparator<K>

    The _comparator property is being returned.

  • get root(): undefined | NODE
  • The function returns the root node of a tree structure.

    Returns undefined | NODE

    The _root property of the object, which is of type NODE or undefined.

  • get size(): number
  • The function returns the size of an object.

    Returns number

    The size of the object, which is a number.

  • get toEntryFn(): undefined | ((rawElement) => BTNEntry<K, V>)
  • The function returns the value of the _toEntryFn property.

    Returns undefined | ((rawElement) => BTNEntry<K, V>)

    The function being returned is this._toEntryFn.

Methods

  • Time Complexity: O(n) Space Complexity: O(1)

    The function is an implementation of the Symbol.iterator method that returns an iterable iterator.

    Parameters

    • Rest ...args: any[]

      The args parameter in the code snippet represents a rest parameter. It allows the function to accept any number of arguments as an array. In this case, the args parameter is used to pass any additional arguments to the _getIterator method.

    Returns IterableIterator<[K, undefined | V]>

  • Time Complexity: O(1) Space Complexity: O(1)

    The function calculates the balance factor of a node in a binary tree.

    Parameters

    • node: NODE

      The parameter "node" is of type "NODE", which likely represents a node in a binary tree data structure.

    Returns number

    the balance factor of a given node. The balance factor is calculated by subtracting the height of the left subtree from the height of the right subtree.

  • Time Complexity: O(1) Space Complexity: O(1)

    The _balanceLL function performs a left-left rotation to balance a binary search tree.

    Parameters

    • A: NODE

      A is a node in a binary tree.

    Returns void

  • Time Complexity: O(1) Space Complexity: O(1)

    The _balanceLR function performs a left-right rotation to balance a binary tree.

    Parameters

    • A: NODE

      A is a node in a binary tree.

    Returns void

  • Time Complexity: O(log n) Space Complexity: O(1)

    The _balancePath function is used to update the heights of nodes and perform rotation operations to restore balance in an AVL tree after inserting a node.

    Parameters

    • node: R | KeyOrNodeOrEntry<K, V, NODE>

      The node parameter can be of type R or KeyOrNodeOrEntry<K, V, NODE>.

    Returns void

  • Time Complexity: O(1) Space Complexity: O(1)

    The function _balanceRL performs a right-left rotation to balance a binary tree.

    Parameters

    • A: NODE

      A is a node in a binary tree.

    Returns void

  • Time Complexity: O(1) Space Complexity: O(1)

    The function _balanceRR performs a right-right rotation to balance a binary tree.

    Parameters

    • A: NODE

      A is a node in a binary tree.

    Returns void

  • Time Complexity: O(n) Space Complexity: O(n)

    The _displayAux function is responsible for generating the display layout of a binary tree node, taking into account various options such as whether to show null, undefined, or NaN nodes.

    Parameters

    • node: undefined | null | NODE

      The node parameter represents a node in a binary tree. It can be of type NODE, null, or undefined.

    • options: BinaryTreePrintOptions

      The options parameter is an object that contains the following properties:

    Returns NodeDisplayLayout

    The function _displayAux returns a NodeDisplayLayout which is an array containing the following elements:

    1. mergedLines: An array of strings representing the lines of the node display.
    2. totalWidth: The total width of the node display.
    3. totalHeight: The total height of the node display.
    4. middleIndex: The index of the middle character
  • Time Complexity: O(1) Space Complexity: O(1)

    The function _ensureCallback ensures that a callback function is provided and returns it.

    Type Parameters

    • C extends BTNCallback<NODE>

    Parameters

    • identifier: undefined | null | ReturnType<C>

      The identifier parameter is of type ReturnType<C> | null | undefined. This means it can accept a value that is the return type of the generic type C, or it can be null or undefined.

    • callback: C = ...

      The callback parameter is a function that takes a node as an argument and returns a value. It is of type C, which is a generic type that extends the BTNCallback<NODE> type.

    Returns C

    the callback parameter.

  • Time Complexity: O(1) Space Complexity: O(1)

    The function _getIterator is a generator function that returns an iterator for the key-value pairs in a binary search tree.

    Parameters

    • node: undefined | null | NODE = ...

      The node parameter represents the current node in the binary search tree. It is initially set to the root node of the tree.

    Returns IterableIterator<[K, undefined | V]>

    an IterableIterator<[K, V | undefined]>.

  • Time Complexity: O(1) Space Complexity: O(1)

    The function replaces an old node with a new node and sets the height of the new node to be the same as the old node.

    Parameters

    • oldNode: NODE

      The oldNode parameter represents the node that needs to be replaced in the data structure.

    • newNode: NODE

      The newNode parameter is the new node that will replace the oldNode in the data structure.

    Returns NODE

    The method is returning the result of calling the _replaceNode method from the superclass, with the oldNode and newNode as arguments.

  • The function sets the root of a tree-like structure and updates the parent property of the new root.

    Parameters

    • v: undefined | NODE

      v is a parameter of type NODE or undefined.

    Returns void

  • Time Complexity: O(1) Space Complexity: O(1)

    The _swapProperties function swaps the key, value, and height properties between two nodes in a binary search tree.

    Parameters

    • srcNode: R | BSTNKeyOrNode<K, NODE>

      The srcNode parameter represents either a node object (NODE) or a key-value pair (R) that is being swapped with another node.

    • destNode: R | BSTNKeyOrNode<K, NODE>

      The destNode parameter is either an instance of R or an instance of BSTNKeyOrNode<K, NODE>.

    Returns undefined | NODE

    The method is returning the destNodeEnsured object if both srcNodeEnsured and destNodeEnsured are truthy. Otherwise, it returns undefined.

  • Time Complexity: O(1) Space Complexity: O(1)

    The function updates the height of a node in a binary tree based on the heights of its left and right children.

    Parameters

    • node: NODE

      The parameter "node" represents a node in a binary tree data structure.

    Returns void

  • Time Complexity: O(log n) Space Complexity: O(1)

    The function overrides the add method of a class and inserts a key-value pair into a data structure, then balances the path.

    Parameters

    • keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>

      The parameter keyOrNodeOrEntryOrRawElement can accept values of type R, KeyOrNodeOrEntry<K, V, NODE>, or RawElement.

    • Optional value: V

      The value parameter is an optional value that you want to associate with the key or node being added to the data structure.

    Returns boolean

    The method is returning a boolean value.

  • Time Complexity: O(k log n) Space Complexity: O(k + log n)

    The addMany function in TypeScript adds multiple keys or nodes to a data structure and returns an array indicating whether each key or node was successfully inserted.

    Parameters

    • keysOrNodesOrEntriesOrRawElements: Iterable<R | KeyOrNodeOrEntry<K, V, NODE>>

      An iterable containing keys, nodes, entries, or raw elements to be added to the data structure.

    • Optional values: Iterable<undefined | V>

      An optional iterable of values to be associated with the keys or nodes being added. If provided, the values will be assigned to the corresponding keys or nodes in the same order. If not provided, undefined will be assigned as the value for each key or node.

    • Optional isBalanceAdd: boolean = true

      A boolean flag indicating whether the tree should be balanced after adding the elements. If set to true, the tree will be balanced using a binary search tree algorithm. If set to false, the elements will be added without balancing the tree. The default value is true.

    • iterationType: IterationType = ...

      The iterationType parameter is an optional parameter that specifies the type of iteration to use when adding multiple keys or nodes to the binary search tree. It can have two possible values:

    Returns boolean[]

    The function addMany returns an array of booleans indicating whether each element was successfully inserted into the data structure.

  • Time complexity: O(n) Space complexity: O(n)

    The function overrides the breadth-first search method and returns an array of the return types of the callback function.

    Type Parameters

    • C extends BTNCallback<NODE>

    Parameters

    • callback: C = ...

      The callback parameter is a function that will be called for each node visited during the breadth-first search. It should take a single argument, which is the current node being visited, and it can return a value of any type.

    • beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = ...

      The beginRoot parameter is the starting point for the breadth-first search. It can be either a root node, a key-value pair, or an entry object. If no value is provided, the default value is the root of the tree.

    • iterationType: IterationType = ...

      The iterationType parameter is used to specify the type of iteration to be performed during the breadth-first search (BFS) traversal. It can have one of the following values:

    Returns ReturnType<C>[]

    an array of the return type of the callback function.

  • Time complexity: O(n) Space complexity: O(n)

    The clone function creates a deep copy of a tree object.

    Returns TREE

    The clone() method is returning a cloned instance of the TREE object.

  • The function creates a new AVL tree node with the given key and value.

    Parameters

    • key: K

      The key parameter is of type K, which represents the key of the node being created.

    • Optional value: V

      The "value" parameter is an optional parameter of type V. It represents the value associated with the key in the node being created.

    Returns NODE

    The method is returning a new instance of the AVLTreeNode class, casted as the generic type NODE.

  • The function creates a new AVL tree with the specified options and returns it.

    Parameters

    • Optional options: AVLTreeOptions<K, V, R>

      The options parameter is an optional object that can be passed to the createTree function. It is used to customize the behavior of the AVL tree that is being created.

    Returns TREE

    a new AVLTree object.

  • Time Complexity: O(log n) Space Complexity: O(1)

    The function overrides the delete method of a binary tree class and performs additional operations to balance the tree after deletion.

    Type Parameters

    • C extends BTNCallback<NODE>

    Parameters

    • identifier: ReturnType<C>

      The identifier parameter is the value or condition used to identify the node(s) to be deleted from the binary tree. It can be of any type that is compatible with the binary tree's node type.

    • callback: C = ...

      The callback parameter is a function that will be used to determine if a node should be deleted or not. It is optional and has a default value of this._DEFAULT_CALLBACK.

    Returns BinaryTreeDeleteResult<NODE>[]

    The method is returning an array of BinaryTreeDeleteResult objects.

  • Time complexity: O(n) Space complexity: O(n)

    The function overrides the depth-first search method and returns an array of the return types of the callback function.

    Type Parameters

    • C extends BTNCallback<NODE>

    Parameters

    • callback: C = ...

      The callback parameter is a function that will be called for each node during the depth-first search traversal. It is an optional parameter and defaults to this._DEFAULT_CALLBACK. The type C represents the type of the callback function.

    • Optional pattern: DFSOrderPattern = 'IN'

      The "pattern" parameter in the code snippet refers to the order in which the Depth-First Search (DFS) algorithm visits the nodes in a tree or graph. It can take one of the following values:

    • beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = ...

      The beginRoot parameter is the starting point for the depth-first search traversal. It can be either a root node, a key-value pair, or a node entry. If not specified, the default value is the root of the tree.

    • Optional iterationType: IterationType = 'ITERATIVE'

      The iterationType parameter specifies the type of iteration to be used during the Depth-First Search (DFS) traversal. It can have one of the following values:

    Returns ReturnType<C>[]

    The method is returning an array of the return type of the callback function.

  • Time Complexity: O(log n) Space Complexity: O(log n)

    The function ensures the existence of a node in a data structure and returns it, or undefined if it doesn't exist.

    Parameters

    • keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>

      The parameter keyOrNodeOrEntryOrRawElement can accept a value of type R, which represents the key, node, entry, or raw element that needs to be ensured in the tree.

    • Optional iterationType: IterationType = 'ITERATIVE'

      The iterationType parameter is an optional parameter that specifies the type of iteration to be used when ensuring a node. It has a default value of 'ITERATIVE'.

    Returns undefined | NODE

    The method is returning either the node that was ensured or undefined if the node could not be ensured.

  • Time Complexity: O(n) Space Complexity: O(n)

    The function returns an iterator that yields key-value pairs from the object, where the value can be undefined.

    Returns IterableIterator<[K, undefined | V]>

  • Time Complexity: O(n) Space Complexity: O(1)

    The every function checks if every element in a collection satisfies a given condition.

    Parameters

    • predicate: EntryCallback<K, undefined | V, boolean>

      The predicate parameter is a callback function that takes three arguments: value, key, and index. It should return a boolean value indicating whether the condition is met for the current element in the iteration.

    • Optional thisArg: any

      The thisArg parameter is an optional argument that specifies the value to be used as this when executing the predicate function. If thisArg is provided, it will be passed as the first argument to the predicate function. If thisArg is not provided

    Returns boolean

    The every method is returning a boolean value. It returns true if every element in the collection satisfies the provided predicate function, and false otherwise.

  • Time Complexity: O(n) Space Complexity: O(n)

    The filter function creates a new tree with entries that pass a given predicate function.

    Parameters

    • predicate: EntryCallback<K, undefined | V, boolean>

      The predicate parameter is a callback function that is used to test each element in the tree. It takes three arguments: value, key, and index. The value argument represents the value of the current element being processed, the key argument represents the key of the

    • Optional thisArg: any

      The thisArg parameter is an optional argument that allows you to specify the value of this within the predicate function. When the predicate function is called, thisArg will be used as the value of this within the function. If thisArg

    Returns TREE

    The filter method is returning a new tree object that contains the entries that pass the given predicate function.

  • Time Complexity: O(n) Space Complexity: O(1)

    The find function iterates over the entries of a collection and returns the first value for which the callback function returns true.

    Parameters

    • callbackfn: EntryCallback<K, undefined | V, [K, undefined | V]>

      The callback function that will be called for each entry in the collection. It takes three arguments: the value of the entry, the key of the entry, and the index of the entry in the collection. It should return a boolean value indicating whether the current entry matches the desired condition.

    • Optional thisArg: any

      The thisArg parameter is an optional argument that specifies the value to be used as this when executing the callbackfn function. If thisArg is provided, it will be passed as the this value to the callbackfn function. If thisArg @returns The method findreturns the value of the first element in the iterable that satisfies the provided callback function. If no element satisfies the callback function,undefined` is returned.

    Returns undefined | [K, undefined | V]

  • Time Complexity: O(n) Space Complexity: O(1)

    The forEach function iterates over each key-value pair in a collection and executes a callback function for each pair.

    Parameters

    • callbackfn: EntryCallback<K, undefined | V, void>

      The callback function that will be called for each element in the collection. It takes four parameters: the value of the current element, the key of the current element, the index of the current element, and the collection itself.

    • Optional thisArg: any

      The thisArg parameter is an optional argument that allows you to specify the value of this within the callback function. If thisArg is provided, it will be used as the this value when calling the callback function. If thisArg is not provided, `

    Returns void

  • Time Complexity: O(n) Space Complexity: O(log n)

    The function get in TypeScript overrides the base class method and returns the value associated with the given identifier.

    Type Parameters

    • C extends BTNCallback<NODE, K>

    Parameters

    • identifier: K

      The identifier parameter is the value used to identify the node in the binary tree. It can be of any type that is returned by the callback function C. It can also be null or undefined if no identifier is provided.

    • Optional callback: C

      The callback parameter is a function that will be used to determine if a node matches the given identifier. It is optional and defaults to this._DEFAULT_CALLBACK.

    • Optional beginRoot: R | KeyOrNodeOrEntry<K, V, NODE>

      The beginRoot parameter is the starting point for the search in the binary tree. It can be either a root node of the tree or a key, node, or entry object that exists in the tree. If no specific starting point is provided, the search will begin from the root of the

    • Optional iterationType: IterationType

      The iterationType parameter is used to specify the type of iteration to be performed when searching for a node in the tree. It can have one of the following values:

    Returns undefined | V

    The method is returning the value associated with the specified identifier in the binary tree.

  • Time Complexity: O(n) Space Complexity: O(log n)

    The function get in TypeScript overrides the base class method and returns the value associated with the given identifier.

    Type Parameters

    • C extends BTNCallback<NODE, NODE>

    Parameters

    • identifier: undefined | null | NODE

      The identifier parameter is the value used to identify the node in the binary tree. It can be of any type that is returned by the callback function C. It can also be null or undefined if no identifier is provided.

    • Optional callback: C

      The callback parameter is a function that will be used to determine if a node matches the given identifier. It is optional and defaults to this._DEFAULT_CALLBACK.

    • Optional beginRoot: R | KeyOrNodeOrEntry<K, V, NODE>

      The beginRoot parameter is the starting point for the search in the binary tree. It can be either a root node of the tree or a key, node, or entry object that exists in the tree. If no specific starting point is provided, the search will begin from the root of the

    • Optional iterationType: IterationType

      The iterationType parameter is used to specify the type of iteration to be performed when searching for a node in the tree. It can have one of the following values:

    Returns undefined | V

    The method is returning the value associated with the specified identifier in the binary tree.

  • Time Complexity: O(n) Space Complexity: O(log n)

    The function get in TypeScript overrides the base class method and returns the value associated with the given identifier.

    Type Parameters

    • C extends BTNCallback<NODE>

    Parameters

    • identifier: ReturnType<C>

      The identifier parameter is the value used to identify the node in the binary tree. It can be of any type that is returned by the callback function C. It can also be null or undefined if no identifier is provided.

    • callback: C

      The callback parameter is a function that will be used to determine if a node matches the given identifier. It is optional and defaults to this._DEFAULT_CALLBACK.

    • Optional beginRoot: R | KeyOrNodeOrEntry<K, V, NODE>

      The beginRoot parameter is the starting point for the search in the binary tree. It can be either a root node of the tree or a key, node, or entry object that exists in the tree. If no specific starting point is provided, the search will begin from the root of the

    • Optional iterationType: IterationType

      The iterationType parameter is used to specify the type of iteration to be performed when searching for a node in the tree. It can have one of the following values:

    Returns undefined | V

    The method is returning the value associated with the specified identifier in the binary tree.

  • Time Complexity: O(n) Space Complexity: O(1)

    The function calculates the depth of a given node or key in a tree-like data structure.

    Parameters

    • dist: R | KeyOrNodeOrEntry<K, V, NODE>

      The dist parameter can be either a R (representing a root node), or a KeyOrNodeOrEntry<K, V, NODE> (representing a key, node, or entry).

    • beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = ...

      The beginRoot parameter is optional and represents the starting point from which to calculate the depth. It can be either a reference to a node in the tree or a key-value pair or an entry object. If not provided, the default value is this.root, which refers to the root node

    Returns number

    the depth of a node in a tree structure.

  • Time Complexity: O(n) Space Complexity: O(1)

    The getHeight function calculates the maximum height of a binary tree using either a recursive or iterative approach.

    Parameters

    • beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = ...

      The beginRoot parameter represents the starting point for calculating the height of a tree. It can be either a root node (R), a key or node or entry (KeyOrNodeOrEntry<K, V, NODE>), or it defaults to the root of the current tree.

    • iterationType: IterationType = ...

      The iterationType parameter determines the type of iteration used to calculate the height of the tree. It can have two possible values:

    Returns number

    the maximum height of the binary tree.

  • Time Complexity: O(log n) Space Complexity: O(1)

    The getLeftMost function returns the leftmost node in a binary tree, either using recursive or iterative traversal.

    Parameters

    • beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = ...

      The beginRoot parameter represents the starting point for finding the leftmost node in a binary tree. It can be either a root node (R), a key or node or entry (KeyOrNodeOrEntry<K, V, NODE>), or null or undefined.

    • iterationType: IterationType = ...

      The iterationType parameter is used to specify the type of iteration to be performed. It can have two possible values:

    Returns undefined | null | NODE

    The function getLeftMost returns the leftmost node in a binary tree.

  • Time Complexity: O(n) Space Complexity: O(log n)

    The getMinHeight function calculates the minimum height of a binary tree using either a recursive or iterative approach.

    Parameters

    • beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = ...

      The beginRoot parameter represents the starting point for calculating the minimum height of a tree. It can be either a root node (R), a key or node or entry (KeyOrNodeOrEntry<K, V, NODE>), or it defaults to the root of the current tree.

    • iterationType: IterationType = ...

      The iterationType parameter determines the type of iteration to be used when calculating the minimum height of the tree. It can have two possible values:

    Returns number

    The function getMinHeight returns a number, which represents the minimum height of the binary tree.

  • Time Complexity: O(log n) Space Complexity: O(1)

    The function getNode returns the first node that matches the given identifier and callback function in a binary search tree.

    Type Parameters

    • C extends BTNCallback<NODE>

    Parameters

    • identifier: undefined | ReturnType<C>

      The identifier parameter is the value that you want to search for in the binary search tree. It can be of any type that is compatible with the type returned by the callback function.

    • callback: C = ...

      The callback parameter is a function that will be used to determine if a node matches the desired criteria. It should be a function that takes a node as an argument and returns a boolean value indicating whether the node matches the criteria or not. If no callback is provided, the default callback will be

    • beginRoot: R | BSTNKeyOrNode<K, NODE> = ...

      The beginRoot parameter is the starting point for the search in the binary search tree. It can be either a key or a node. If it is a key, the search will start from the node with that key. If it is a node, the search will start from that node.

    • iterationType: IterationType = ...

      The iterationType parameter is used to specify the type of iteration to be performed when searching for nodes in the binary search tree. It can have one of the following values:

    Returns undefined | NODE

    The method is returning a NODE object or undefined.

  • Time Complexity: O(log n) Space Complexity: O(1)

    The function getNodeByKey returns a node with a specific key from a tree data structure.

    Parameters

    • key: K

      The key parameter is the value used to search for a specific node in the tree. It is typically a unique identifier or a value that can be used to determine the position of the node in the tree structure.

    • Optional iterationType: IterationType = 'ITERATIVE'

      The iterationType parameter is an optional parameter that specifies the type of iteration to be used when searching for a node in the tree. It has a default value of 'ITERATIVE'.

    Returns undefined | NODE

    The method is returning a NODE object or undefined.

  • Time Complexity: O(log n) Space Complexity: O(k + log n)

    The getNodes function in TypeScript retrieves nodes from a binary tree based on a given identifier and callback function.

    Type Parameters

    • C extends BTNCallback<NODE>

    Parameters

    • identifier: undefined | ReturnType<C>

      The identifier parameter is the value that you want to search for in the binary tree. It can be of any type that is returned by the callback function.

    • callback: C = ...

      The callback parameter is a function that takes a node as input and returns a value. This value is used to identify the nodes that match the given identifier. The callback function is optional and defaults to this._DEFAULT_CALLBACK.

    • Optional onlyOne: boolean = false

      A boolean value indicating whether to return only the first matching node or all matching nodes. If set to true, only the first matching node will be returned. If set to false, all matching nodes will be returned. The default value is false.

    • beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = ...

      The beginRoot parameter is the starting point for the search in the binary tree. It can be either a node object, a key-value pair, or an entry object. If it is not provided, the root of the binary tree is used as the starting point.

    • iterationType: IterationType = ...

      The iterationType parameter determines the type of iteration to be performed. It can have two possible values:

    Returns NODE[]

    The method getNodes returns an array of NODE objects.

  • Time Complexity: O(log n) Space Complexity: O(log n)

    The function getPathToRoot returns an array of nodes starting from a given node and traversing up to the root node, with an option to reverse the order of the nodes.

    Parameters

    • beginNode: R | KeyOrNodeOrEntry<K, V, NODE>

      The beginNode parameter can be either of type R or KeyOrNodeOrEntry<K, V, NODE>.

    • Optional isReverse: boolean = true

      The isReverse parameter is a boolean flag that determines whether the resulting path should be reversed or not. If isReverse is set to true, the path will be reversed before returning it. If isReverse is set to false or not provided, the path will

    Returns NODE[]

    The function getPathToRoot returns an array of NODE objects.

  • Time Complexity: O(log n) Space Complexity: O(1)

    The function returns the predecessor node of a given node in a binary tree.

    Parameters

    • node: NODE

      The parameter "node" is of type "NODE", which represents a node in a binary tree.

    Returns NODE

    the predecessor node of the given node.

  • Time Complexity: O(log n) Space Complexity: O(1)

    The getRightMost function returns the rightmost node in a binary tree, either recursively or iteratively.

    Parameters

    • beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = ...

      The beginRoot parameter represents the starting point for finding the rightmost node in a binary tree. It can be either a root node (R), a key or node or entry (KeyOrNodeOrEntry<K, V, NODE>), or null or undefined.

    • iterationType: IterationType = ...

      The iterationType parameter is used to specify the type of iteration to be performed when finding the rightmost node in a binary tree. It can have two possible values:

    Returns undefined | null | NODE

    The function getRightMost returns a NODE object, null, or undefined.

  • Time Complexity: O(log n) Space Complexity: O(1)

    The function getSuccessor returns the next node in a binary tree given a current node.

    Parameters

    • Optional x: null | K | NODE

      The parameter x can be of type K, NODE, or null.

    Returns undefined | null | NODE

    The function getSuccessor returns a NODE object if a successor exists, null if there is no successor, and undefined if the input x is not a valid node.

  • Time Complexity: O(n) Space Complexity: O(log n)

    The has function checks if a given identifier exists in the data structure and returns a boolean value.

    Type Parameters

    • C extends BTNCallback<NODE, K>

    Parameters

    • identifier: K

      The identifier parameter is the value used to identify a specific node or entry in the data structure. It can be of any type that is returned by the callback function C. It can also be null or undefined if no specific identifier is provided.

    • Optional callback: C

      The callback parameter is a function that will be used to determine whether a node should be included in the result or not. It is of type C, which extends the BTNCallback<NODE> type.

    • Optional beginRoot: R | KeyOrNodeOrEntry<K, V, NODE>

      The beginRoot parameter is the starting point for the iteration in the data structure. It can be either a root node, a key-value pair, or a node entry. If not specified, it defaults to the root of the data structure.

    • Optional iterationType: IterationType

      The iterationType parameter is used to specify the type of iteration to be performed. It is an optional parameter with a default value of IterationType.

    Returns boolean

    The method is returning a boolean value.

  • Time Complexity: O(n) Space Complexity: O(log n)

    The has function checks if a given identifier exists in the data structure and returns a boolean value.

    Type Parameters

    • C extends BTNCallback<NODE, NODE>

    Parameters

    • identifier: undefined | null | NODE

      The identifier parameter is the value used to identify a specific node or entry in the data structure. It can be of any type that is returned by the callback function C. It can also be null or undefined if no specific identifier is provided.

    • Optional callback: C

      The callback parameter is a function that will be used to determine whether a node should be included in the result or not. It is of type C, which extends the BTNCallback<NODE> type.

    • Optional beginRoot: R | KeyOrNodeOrEntry<K, V, NODE>

      The beginRoot parameter is the starting point for the iteration in the data structure. It can be either a root node, a key-value pair, or a node entry. If not specified, it defaults to the root of the data structure.

    • Optional iterationType: IterationType

      The iterationType parameter is used to specify the type of iteration to be performed. It is an optional parameter with a default value of IterationType.

    Returns boolean

    The method is returning a boolean value.

  • Time Complexity: O(n) Space Complexity: O(log n)

    The has function checks if a given identifier exists in the data structure and returns a boolean value.

    Type Parameters

    • C extends BTNCallback<NODE>

    Parameters

    • identifier: undefined | null | ReturnType<C>

      The identifier parameter is the value used to identify a specific node or entry in the data structure. It can be of any type that is returned by the callback function C. It can also be null or undefined if no specific identifier is provided.

    • callback: C

      The callback parameter is a function that will be used to determine whether a node should be included in the result or not. It is of type C, which extends the BTNCallback<NODE> type.

    • Optional beginRoot: R | KeyOrNodeOrEntry<K, V, NODE>

      The beginRoot parameter is the starting point for the iteration in the data structure. It can be either a root node, a key-value pair, or a node entry. If not specified, it defaults to the root of the data structure.

    • Optional iterationType: IterationType

      The iterationType parameter is used to specify the type of iteration to be performed. It is an optional parameter with a default value of IterationType.

    Returns boolean

    The method is returning a boolean value.

  • Time Complexity: O(n) Space Complexity: O(1)

    The function checks if a given value exists in a collection.

    Parameters

    • value: undefined | V

      The parameter "value" is the value that we want to check if it exists in the collection.

    Returns boolean

    a boolean value, either true or false.

  • Time Complexity: O(n) Space Complexity: O(log n)

    The function isAVLBalanced checks if a binary tree is AVL balanced using either a recursive or iterative approach.

    Parameters

    • iterationType: IterationType = ...

      The iterationType parameter is an optional parameter that specifies the type of iteration to use when checking if the AVL tree is balanced. It has a default value of this.iterationType, which means it will use the iteration type specified in the current instance of the AVL tree.

    Returns boolean

    a boolean value.

  • Time Complexity: O(n) Space Complexity: O(1)

    The function isBST checks if a binary search tree is valid, either recursively or iteratively.

    Parameters

    • beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = ...

      The beginRoot parameter represents the starting point for checking if a binary search tree (BST) is valid. It can be either a root node of the BST, a key value of a node in the BST, or an entry object containing both the key and value of a node in the BST

    • iterationType: IterationType = ...

      The iterationType parameter is used to determine the type of iteration to be performed while checking if the binary search tree (BST) is valid. It can have two possible values:

    Returns boolean

    a boolean value.

  • Time Complexity: O(1) Space Complexity: O(1)

    Check if the binary tree is empty.

    Returns boolean

    • True if the binary tree is empty, false otherwise.
  • The function checks if the input is an array with two elements, indicating it is a binary tree node entry.

    Parameters

    • keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>

      The parameter keyOrNodeOrEntryOrRawElement can be of type R or KeyOrNodeOrEntry<K, V, NODE>.

    Returns keyOrNodeOrEntryOrRawElement is BTNEntry<K, V>

    a boolean value.

  • The function checks if a given value is a valid key by evaluating its type and value.

    Parameters

    • key: any

      The key parameter can be of any type. It is the value that we want to check if it is a valid key.

    • Optional isCheckValueOf: boolean = true

      The isCheckValueOf parameter is a boolean flag that determines whether the function should check the valueOf() method of an object when the key is of type 'object'. If isCheckValueOf is true, the function will recursively call itself with the value returned by key.valueOf().

    Returns key is K

    a boolean value.

  • The function checks if a given node is equal to the NIL value.

    Parameters

    • node: R | KeyOrNodeOrEntry<K, V, NODE>

      The parameter node can be of type R or KeyOrNodeOrEntry<K, V, NODE>.

    Returns boolean

    a boolean value.

  • The function checks if the input is an instance of AVLTreeNode.

    Parameters

    • keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>

      The parameter keyOrNodeOrEntryOrRawElement can be of type R or KeyOrNodeOrEntry<K, V, NODE>.

    Returns keyOrNodeOrEntryOrRawElement is NODE

    a boolean value indicating whether the input parameter keyOrNodeOrEntryOrRawElement is an instance of the AVLTreeNode class.

  • The function checks if a given node is a real node or null.

    Parameters

    • node: R | KeyOrNodeOrEntry<K, V, NODE>

      The parameter node can be of type R or KeyOrNodeOrEntry<K, V, NODE>.

    Returns node is null | NODE

    a boolean value.

  • Time Complexity: O(n) Space Complexity: O(log n)

    The function checks if a binary tree is perfectly balanced by comparing the minimum height and the height of the tree.

    Parameters

    • beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = ...

      The parameter beginRoot is optional and has a default value of this.root. It represents the starting point for checking if the tree is perfectly balanced. It can be either a root node (R), a key or node or entry (`KeyOrNodeOrEntry<K, V, NODE

    Returns boolean

    a boolean value.

  • The function checks if a given node is a valid node in a binary search tree.

    Parameters

    • node: R | KeyOrNodeOrEntry<K, V, NODE>

      The parameter node can be of type R or KeyOrNodeOrEntry<K, V, NODE>.

    Returns node is NODE

    a boolean value.

  • The function overrides a method and converts a key, value pair or entry or raw element to a node.

    Parameters

    • keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>

      A variable that can be of type R or KeyOrNodeOrEntry<K, V, NODE>. It represents either a key, a node, an entry, or a raw element.

    • Optional value: V

      The value parameter is an optional value of type V. It represents the value associated with a key in a key-value pair.

    Returns undefined | NODE

    either a NODE object or undefined.

  • Time Complexity: O(n) Space Complexity: O(n)

    The function returns an iterator that yields the keys of a data structure.

    Returns IterableIterator<K>

  • Time complexity: O(n) Space complexity: O(n)

    The lesserOrGreaterTraverse function traverses a binary tree and applies a callback function to each node that meets a certain condition based on a target node and a comparison value.

    Type Parameters

    • C extends BTNCallback<NODE>

    Parameters

    • callback: C = ...

      The callback parameter is a function that will be called for each node that meets the condition specified by the lesserOrGreater parameter. It takes a single argument, which is the current node being traversed, and returns a value of any type.

    • lesserOrGreater: CP = -1

      The lesserOrGreater parameter is used to determine whether to traverse nodes that are lesser, greater, or both than the targetNode. It accepts the values -1, 0, or 1, where:

    • targetNode: R | KeyOrNodeOrEntry<K, V, NODE> = ...

      The targetNode parameter is the node in the binary tree that you want to start traversing from. It can be specified either by providing the key of the node, the node itself, or an entry containing the key and value of the node. If no targetNode is provided,

    • iterationType: IterationType = ...

      The iterationType parameter determines the type of traversal to be performed on the binary tree. It can have two possible values:

    Returns ReturnType<C>[]

    The function lesserOrGreaterTraverse returns an array of values of type ReturnType<C>, which is the return type of the callback function passed as an argument.

  • Time complexity: O(n) Space complexity: O(n)

    The function overrides the listLevels method from the superclass and returns an array of arrays containing the results of the callback function applied to each level of the tree.

    Type Parameters

    • C extends BTNCallback<NODE>

    Parameters

    • callback: C = ...

      The callback parameter is a generic type C that extends BTNCallback<NODE>. It represents a callback function that will be called for each node in the tree during the iteration process.

    • beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = ...

      The beginRoot parameter is the starting point for listing the levels of the binary tree. It can be either a root node of the tree, a key-value pair representing a node in the tree, or a key representing a node in the tree. If no value is provided, the root of

    • iterationType: IterationType = ...

      The iterationType parameter is used to specify the type of iteration to be performed on the tree. It can have one of the following values:

    Returns ReturnType<C>[][]

    The method is returning a two-dimensional array of the return type of the callback function.

  • Time Complexity: O(n) Space Complexity: O(n)

    The map function creates a new tree by applying a callback function to each entry in the current tree.

    Parameters

    • callback: EntryCallback<K, undefined | V, V>

      The callback parameter is a function that will be called for each entry in the tree. It takes three arguments: value, key, and index. The value argument represents the value of the current entry, the key argument represents the key of the current entry, and the index argument represents the index of the

    • Optional thisArg: any

      The thisArg parameter is an optional argument that specifies the value to be used as this when executing the callback function. If thisArg is provided, it will be passed as the this value to the callback function. If thisArg is

    Returns TREE

    The map method is returning a new tree object.

  • Time complexity: O(n) Space complexity: O(n)

    The morris function performs a depth-first traversal on a binary tree using the Morris traversal algorithm.

    Type Parameters

    • C extends BTNCallback<NODE>

    Parameters

    • callback: C = ...

      The callback parameter is a function that will be called for each node in the tree. It takes a single argument, which is the current node, and can return any value. The return type of the callback function is determined by the ReturnType<C> type, which represents the return

    • Optional pattern: DFSOrderPattern = 'IN'

      The pattern parameter in the morris function is used to specify the order in which the nodes of a binary tree are traversed. It can take one of the following values:

    • beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = ...

      The beginRoot parameter is the starting point for the traversal. It can be either a node object, a key, or an entry object. If no value is provided, the root of the tree is used as the starting point.

    Returns ReturnType<C>[]

    The function morris returns an array of values that are the return values of the callback function callback.

  • Time complexity: O(n) Space complexity: O(n)

    The perfectlyBalance function takes an optional iterationType parameter and returns true if the binary search tree is perfectly balanced, otherwise it returns false.

    Parameters

    • iterationType: IterationType = ...

      The iterationType parameter is an optional parameter that specifies the type of iteration to use when building a balanced binary search tree. It has a default value of this.iterationType, which means it will use the iteration type specified in the current instance of the class.

    Returns boolean

    The function perfectlyBalance returns a boolean value.

  • Time Complexity: O(n) Space Complexity: O(n)

    The print function in TypeScript prints the binary tree structure with customizable options.

    Parameters

    • beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = ...

      The beginRoot parameter is the starting point for printing the binary tree. It can be either a node of the binary tree or a key or entry that exists in the binary tree. If no value is provided, the root of the binary tree will be used as the starting point.

    • Optional options: BinaryTreePrintOptions

      The options parameter is an optional object that allows you to customize the printing behavior. It has the following properties:

    Returns void

    Nothing is being returned. The function has a return type of void, which means it does not return any value.

  • Time Complexity: O(n) Space Complexity: O(1)

    The reduce function iterates over key-value pairs and applies a callback function to each pair, accumulating a single value.

    Type Parameters

    • U

    Parameters

    • callbackfn: ReduceEntryCallback<K, undefined | V, U>

      The callback function that will be called for each element in the collection. It takes four arguments: the current accumulator value, the current value of the element, the key of the element, and the index of the element in the collection. It should return the updated accumulator value.

    • initialValue: U

      The initialValue parameter is the initial value of the accumulator. It is the value that will be used as the first argument to the callbackfn function when reducing the elements of the collection.

    Returns U

    The reduce method is returning the final value of the accumulator after iterating over all the elements in the collection.

  • Time Complexity: O(k * n) Space Complexity: O(1)

    The refill function clears the current data and adds new data to the collection.

    Parameters

    • keysOrNodesOrEntriesOrRawElements: Iterable<R | KeyOrNodeOrEntry<K, V, NODE>>

      An iterable collection of keys, nodes, entries, or raw elements. These can be of any type (R) or a specific type (KeyOrNodeOrEntry<K, V, NODE>).

    • Optional values: Iterable<undefined | V>

      The values parameter is an optional iterable of values that will be associated with the keys or nodes being added. If provided, the values will be assigned to the corresponding keys or nodes. If not provided, the values will be set to undefined.

    Returns void

  • Time Complexity: O(n) Space Complexity: O(1)

    The "some" function iterates over a collection and returns true if at least one element satisfies a given predicate.

    Parameters

    • predicate: EntryCallback<K, undefined | V, boolean>

      The predicate parameter is a callback function that takes three arguments: value, key, and index. It should return a boolean value indicating whether the condition is met for the current element in the iteration.

    • Optional thisArg: any

      The thisArg parameter is an optional argument that specifies the value to be used as the this value when executing the predicate function. If thisArg is provided, it will be passed as the first argument to the predicate function. If thisArg is

    Returns boolean

    a boolean value. It returns true if the predicate function returns true for any pair in the collection, and false otherwise.

  • Time Complexity: O(n) Space Complexity: O(n)

    The function returns an iterator that yields the values of a collection.

    Returns IterableIterator<undefined | V>

Generated using TypeDoc