The keysNodesEntriesOrRaws
parameter in the constructor is an
iterable that can contain either key-value pairs represented as BTNRep<K, V[], AVLTreeMultiMapNode<K, V>>
or raw data represented as R
. This parameter is used to initialize
the AVLTreeMulti
Optional
options: AVLTreeMultiMapOptions<K, V[], R>The options
parameter in the constructor is of type
AVLTreeMultiMapOptions<K, V[], R>
. It is an optional parameter that allows you to specify
additional options for configuring the AVLTreeMultiMap instance.
Protected
_balanceTime Complexity: O(1) Space Complexity: O(1)
The function calculates the balance factor of a node in a binary tree.
The parameter "node" is of type "AVLTreeNode<K, V>", which likely represents a node in a binary tree data structure.
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.
Protected
_balanceLLTime Complexity: O(1) Space Complexity: O(1)
The _balanceLL
function performs a left-left rotation to balance a binary search tree.
A is a node in a binary tree.
Protected
_balanceLRTime Complexity: O(1) Space Complexity: O(1)
The _balanceLR
function performs a left-right rotation to balance a binary tree.
A is a node in a binary tree.
Protected
_balanceProtected
_balanceRLTime Complexity: O(1) Space Complexity: O(1)
The function _balanceRL
performs a right-left rotation to balance a binary tree.
A is a node in a binary tree.
Protected
_balanceRRTime Complexity: O(1) Space Complexity: O(1)
The function _balanceRR
performs a right-right rotation to balance a binary tree.
A is a node in a binary tree.
Protected
_clearProtected
_clearProtected
_compareTime Complexity: O(1) Space Complexity: O(1)
The _compare function compares two values using a specified comparator function and optionally reverses the result.
The _compare
method is returning the result of the ternary expression. If _isReverse
is true, it returns the negation of the result of calling the _comparator
function with
arguments a
and b
. If _isReverse
is false, it returns the result of calling the
_comparator
function with arguments a
and b
.
Protected
_dfsThe callback
parameter in the _dfs
method is a function that will be
called on each node visited during the depth-first search traversal. It is a generic type C
that
extends NodeCallback<BinaryTreeNode<K, V> | null>
. The default value for callback
Optional
pattern: DFSOrderPatternThe pattern
parameter in the _dfs
method specifies the
order in which the nodes are visited during a depth-first search traversal. It can have one of the
following values:
Optional
onlyOne: booleanThe onlyOne
parameter in the _dfs
method is a boolean flag
that determines whether the traversal should stop after processing a single node. If onlyOne
is
set to true
, the traversal will return as soon as a single node is processed. If it is set to
false @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} startNode - The
startNodeparameter in the
_dfsmethod is used to specify the starting node for the depth-first search traversal. It can be provided in different forms: @param {IterationType} iterationType - The
iterationTypeparameter in the
_dfsmethod specifies whether the traversal should be done recursively or iteratively. It can have two possible values: @param [includeNull=false] - The
includeNullparameter in the
_dfsmethod determines whether null nodes should be included in the traversal process. If
includeNullis set to
true, the method will consider null nodes as valid nodes to visit or process. If
includeNullis set to
false, @param shouldVisitLeft - The
shouldVisitLeftparameter in the
_dfsmethod is a function that determines whether the left child of a node should be visited during the Depth-First Search traversal. By default, it checks if the node is not null or undefined before visiting the left child. You can customize this behavior @param shouldVisitRight - The
shouldVisitRightparameter in the
_dfsmethod is a function that determines whether to visit the right child node of the current node during a depth-first search traversal. The default implementation of this function checks if the node is not null or undefined before deciding to visit it. @param shouldVisitRoot - The
shouldVisitRootparameter in the
_dfsmethod is a function that determines whether a given node should be visited during the depth-first search traversal. The function takes a node as an argument and returns a boolean value indicating whether the node should be visited. @param shouldProcessRoot - The
shouldProcessRootparameter in the
_dfsmethod is a function that determines whether the root node should be processed during the Depth-First Search traversal. It takes a node (BinaryTreeNode<K, V> | null | undefined) as input and returns a boolean value. If the function @returns The
_dfsmethod returns an array of the return type of the provided callback function
C`.
Optional
startNode: Optional
iterationType: IterationTypeOptional
includeNull: booleanOptional
shouldVisitLeft: ((node: undefined | null | BinaryTreeNode<K, V[]>) => boolean)Optional
shouldVisitRight: ((node: undefined | null | BinaryTreeNode<K, V[]>) => boolean)Optional
shouldVisitRoot: ((node: undefined | null | BinaryTreeNode<K, V[]>) => boolean)Optional
shouldProcessRoot: ((node: undefined | null | BinaryTreeNode<K, V[]>) => boolean)Protected
_displayTime Complexity: O(n) Space Complexity: O(n)
The function _displayAux
in TypeScript is responsible for generating the display layout of nodes
in a binary tree based on specified options.
The node
parameter in the _displayAux
function represents a node in a binary
tree. It can be either a valid node containing a key or a special type of node like null,
undefined, or a Red-Black tree NIL node. The function checks the type of the node and its
The options
parameter in the _displayAux
function
contains the following properties:
The _displayAux
function returns a NodeDisplayLayout
, which is an array containing
information about how to display a node in a binary tree. The NodeDisplayLayout
consists of four
elements:
Protected
_ensureThe
_ensurePredicate
method in the provided code snippet is responsible for ensuring that the input
parameter keyNodeEntryOrPredicate
is transformed into a valid predicate function that can be
used for filtering nodes in a binary tree.
A NodePredicate<BinaryTreeNode<K, V>> function is being returned.
Protected
_extractTime Complexity: O(1) Space Complexity: O(1)
The function _extractKey
in TypeScript returns the key from a given input, which can be a node,
entry, raw data, or null/undefined.
The _extractKey
method you provided is a
TypeScript method that takes in a parameter keyNodeOrEntry
of type K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined
,
where BTNRep
is a generic type with keys K
, V
, and BinaryTreeNode<K, V>
, and @returns The
_extractKeymethod returns the key value extracted from the
keyNodeOrEntryparameter. The return value can be a key value of type
K,
null, or
undefined`, depending on
the conditions checked in the method.
Protected
_getTime Complexity: O(1) Space Complexity: O(1)
The function _getIterator
returns an iterable iterator for a binary tree data structure, either
using an iterative approach or a recursive approach based on the specified iteration type.
The node
parameter in the _getIterator
method represents the current node being
processed during iteration. It is initially set to the root node of the data structure (or the
node passed as an argument), and then it is traversed through the data structure based on the
iteration type specified (ITER @returns The
_getIteratormethod returns an IterableIterator containing key-value pairs of nodes in a binary tree structure. The method uses an iterative approach to traverse the tree based on the
iterationTypeproperty. If the
iterationTypeis set to 'ITERATIVE', the method uses a stack to perform an in-order traversal of the tree. If the
iterationType` is not 'ITERATIVE
Protected
_isTime Complexity: O(1) Space Complexity: O(1)
The function _isPredicate
checks if a given parameter is a function.
The parameter p
is a variable of type any
, which means it can hold any type
of value. In this context, the function _isPredicate
is checking if p
is a function that
satisfies the type NodePredicate<BinaryTreeNode<K, V>>
.
The function is checking if the input p
is a function and returning a boolean value
based on that check. If p
is a function, it will return true
, indicating that p
is a
predicate function for a binary tree node. If p
is not a function, it will return false
.
Protected
_keyTime Complexity: O(1) Space Complexity: O(1)
The function overrides a method and converts a key, value pair or entry or raw element to a node.
A variable that can be of type R or K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined . 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.
either a BSTNode<K, V> object or undefined.
Protected
_replaceTime 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.
The oldNode
parameter represents the node that needs to be replaced in
the data structure.
The newNode
parameter is the new node that will replace the oldNode
in
the data structure.
The method is returning the result of calling the _replaceNode
method from the
superclass, with the oldNode
and newNode
as arguments.
Protected
_setProtected
_setTime Complexity: O(1) Space Complexity: O(1)
The function _setValue
sets a value in a store based on a key, handling cases where the key or
value is null or undefined.
The method _setValue
returns false
if either the key
is null
or undefined
, or
if the value
is undefined
. Otherwise, it returns the result of calling the set
method on the
_store
object with the key
and value
arguments.
Protected
_swapTime 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.
The srcNode
parameter represents either a node
object (AVLTreeNode<K, V>
) or a key-value pair (R
) that is being swapped with another node.
The destNode
parameter is either an instance of
R
or an instance of BSTNOptKeyOrNode<K, AVLTreeNode<K, V>>
.
The method is returning the destNodeEnsured
object if both srcNodeEnsured
and
destNodeEnsured
are truthy. Otherwise, it returns undefined
.
Protected
_updateTime 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.
The parameter "node" represents a node in a binary tree data structure.
Time Complexity: O(n) Space Complexity: O(1)
The function is an implementation of the Symbol.iterator method that returns an iterable iterator.
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.
Time Complexity: O(log n) Space Complexity: O(log n)
The function overrides the add method of a class and inserts a key-value pair into a data structure, then balances the path.
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.
An iterable containing keys, nodes, entries, or raw elements to be added to the data structure.
Optional
values: Iterable<undefined | V[], any, any>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 = trueA 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.
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:
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.
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.
The startNode
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.
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:
an array of the return type of the callback function.
Time Complexity: O(1) Space Complexity: O(1)
The function createNode
overrides the method to create a new AVLTreeMultiMapNode with a
specified key and an empty array of values.
The key
parameter in the createNode
method represents the key of the node
that will be created in the AVLTreeMultiMap.
An AVLTreeMultiMapNode object is being returned, initialized with the provided key and an empty array.
Time Complexity: O(1) Space Complexity: O(1)
The function createTree
in TypeScript overrides the creation of an AVLTreeMultiMap with
specified options.
Optional
options: AVLTreeMultiMapOptions<K, V[], R>The options
parameter in the createTree
function is of type
AVLTreeMultiMapOptions<K, V[], R>
. This means it is an object that can have properties of type
K
, V[]
, and R
. The function creates a new AVL @returns The
createTreemethod is returning a new instance of
AVLTreeMultiMap` with the
provided options.
Time Complexity: O(log n) Space Complexity: O(log n)
The function overrides the delete method in a TypeScript class, performs deletion, and then balances the tree if necessary.
The delete
method is being overridden in this code snippet. It first calls the delete
method from the superclass (presumably a parent class) with the provided predicate
, which could
be a key, node, entry, or a custom predicate. The result of this deletion operation is stored in
deletedResults
, which is an array of BinaryTreeDeleteResult
objects.
Time Complexity: O(log n) Space Complexity: O(log n)
The function deleteValue
removes a specific value from a key in an AVLTreeMultiMap data
structure and deletes the entire node if no values are left for that key.
The keyNodeOrEntry
parameter in the deleteValue
function can be either a BTNRep
object representing a key-value
pair in the AVLTreeMultiMapNode, or just the key itself.
The value
parameter in the deleteValue
function represents the specific
value that you want to delete from the multi-map data structure associated with a particular key.
The function checks if the value exists in the array of values associated with the key, and if
found, removes it from the array.
The deleteValue
function returns a boolean value. It returns true
if the specified
value
was successfully deleted from the array of values associated with the keyNodeOrEntry
. If
the value was not found in the array, it returns false
.
Time complexity: O(n) Space complexity: O(n)
The function dfs
in TypeScript overrides the base class method with default parameters and
returns the result of the super class dfs
method.
The callback
parameter is a function that will be called for each node
visited during the Depth-First Search traversal. It is a generic type C
that extends the
NodeCallback
interface for BSTNode<K, V>
. The default value for callback
is this._ @param {DFSOrderPattern} [pattern=IN] - The
patternparameter in the
override dfsmethod specifies the order in which the Depth-First Search (DFS) traversal should be performed on the Binary Search Tree (BST). The possible values for the
patternparameter are: @param {boolean} [onlyOne=false] - The
onlyOneparameter in the
override dfsmethod is a boolean flag that indicates whether you want to stop the depth-first search traversal after finding the first matching node or continue searching for all matching nodes. If
onlyOneis set to
true, the traversal will stop after finding @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} startNode - The
startNodeparameter in the
override dfsmethod can be one of the following types: @param {IterationType} iterationType - The
iterationTypeparameter in the
override dfsmethod specifies the type of iteration to be performed during the Depth-First Search (DFS) traversal of a Binary Search Tree (BST). It is used to determine the order in which nodes are visited during the traversal. The possible values for
Optional
pattern: DFSOrderPattern = 'IN'Optional
onlyOne: boolean = falseThe override
function is returning the result of calling the dfs
method from the
superclass, with the provided arguments callback
, pattern
, onlyOne
, startNode
, and
iterationType
. The return type is an array of the return type of the callback function C
.
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.
The parameter
keyNodeOrEntry
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 = ...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'
.
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(1)
The every
function checks if every element in a collection satisfies a given condition.
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: anyThe 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
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 iterates over key-value pairs in a tree data structure and creates a new
tree with elements that satisfy a given predicate.
The predicate
parameter in the filter
method is a function that will be
called with four arguments: the value
of the current entry, the key
of the current entry, the
index
of the current entry in the iteration, and the reference to the tree itself (@param {any} [thisArg] - The
thisArgparameter in the
filtermethod allows you to specify the value of
thisthat should be used when executing the
predicatefunction. This is useful when the
predicatefunction relies on the context of a specific object or value. By providing a
thisArg
Optional
thisArg: anyThe filter
method is returning a new tree that contains entries that pass the provided
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.
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: anyThe 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.
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.
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: anyThe 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, `
Time Complexity: O(n) Space Complexity: O(log n)
This function overrides the get
method to retrieve the value associated with a specified key,
node, entry, raw data, or predicate in a data structure.
The keyNodeEntryOrPredicate
parameter in the get
method can accept one of the
following types:
The startNode
parameter in the get
method is used to specify the starting point for searching for a key or node in the binary tree.
If no specific starting point is provided, the default starting point is the root of the binary
tree (this._root
).
The iterationType
parameter in the get
method is used
to specify the type of iteration to be performed when searching for a key in the binary tree. It
is an optional parameter with a default value of this.iterationType
, which means it will use the
iteration type defined in the
The get
method is returning the value associated with the specified key, node, entry,
raw data, or predicate in the binary tree map. If the specified key or node is found in the tree,
the method returns the corresponding value. If the key or node is not found, it returns
undefined
.
Time Complexity: O(n) Space Complexity: O(log n)
The getDepth
function calculates the depth between two nodes in a binary tree.
The dist
parameter in the getDepth
function represents the node or entry in a binary tree map, or a reference to a node in the tree.
It is the target node for which you want to calculate the depth from the startNode
node.
The startNode
parameter in the
getDepth
function represents the starting point from which you want to calculate the depth of a
given node or entry in a binary tree. If no specific starting point is provided, the default value
for startNode
is set to the root of the binary
The getDepth
method returns the depth of a given node dist
relative to the
startNode
node in a binary tree. If the dist
node is not found in the path to the startNode
node, it returns the depth of the dist
node from the root of the tree.
Time Complexity: O(n) Space Complexity: O(log n)
The getHeight
function calculates the maximum height of a binary tree using either a recursive
or iterative approach in TypeScript.
The startNode
parameter is the starting
point from which the height of the binary tree will be calculated. It can be a node in the binary
tree or a reference to the root of the tree. If not provided, it defaults to the root of the
binary tree data structure.
The iterationType
parameter is used to determine the type
of iteration to be performed while calculating the height of the binary tree. It can have two
possible values:
The getHeight
method returns the height of the binary tree starting from the specified
root node. The height is calculated based on the maximum depth of the tree, considering either a
recursive approach or an iterative approach depending on the iterationType
parameter.
Time Complexity: O(log n) Space Complexity: O(log n)
The function getLeftMost
retrieves the leftmost node in a binary tree using either recursive or
tail-recursive iteration.
The callback
parameter is a function that will be called with the leftmost
node of a binary tree or with undefined
if the tree is empty. It is provided with a default
value of _DEFAULT_NODE_CALLBACK
if not specified.
The startNode
parameter in the
getLeftMost
function represents the starting point for finding the leftmost node in a binary
tree. It can be either a key, a node, or an entry in the binary tree structure. If no specific
starting point is provided, the function will default
The iterationType
parameter in the getLeftMost
function
specifies the type of iteration to be used when traversing the binary tree nodes. It can have two
possible values:
The getLeftMost
function returns the result of the callback function C
applied to the
leftmost node in the binary tree starting from the startNode
node. If the startNode
node is
NIL
, it returns the result of the callback function applied to undefined
. If the startNode
node is not a real node, it returns the result of the callback
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 in TypeScript.
The startNode
parameter in the
getMinHeight
function represents the starting node from which the minimum height of the binary
tree will be calculated. It is either a node in the binary tree or a reference to the root of the
tree. If not provided, the default value is the root
The iterationType
parameter in the getMinHeight
method
specifies the type of iteration to use when calculating the minimum height of a binary tree. It
can have two possible values:
The getMinHeight
method returns the minimum height of the binary tree starting from the
specified root node. The height is calculated based on the shortest path from the root node to a
leaf node in the tree. The method uses either a recursive approach or an iterative approach (using
a stack) based on the iterationType
parameter.
Time Complexity: O(log n) Space Complexity: O(log n)
This function retrieves a node based on a given keyNodeEntryOrPredicate within a binary search tree structure.
The keyNodeEntryOrPredicate
parameter can be of type K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined
, R
, or NodePredicate<BSTNode<K, V>>
.
The startNode
parameter in the getNode
method
is used to specify the starting point for searching nodes in the binary search tree. If no
specific starting point is provided, the default value is set to this._root
, which is the root
node of the binary search tree.
The iterationType
parameter in the getNode
method is a
parameter that specifies the type of iteration to be used. It has a default value of
this.iterationType
, which means it will use the iteration type defined in the class instance if
no value is provided when calling the method.
The getNode
method is returning an optional binary search tree node (OptNode<BSTNode<K, V>>
).
It is using the getNodes
method to find the node based on the provided keyNodeEntryOrPredicate, beginning at
the specified root node (startNode
) and using the specified iteration type. The method then
returns the first node found or undefined
if no node is found.
The getNodes
function you provided takes several parameters:
Optional
onlyOne: booleanThe onlyOne
parameter in the getNodes
function is a boolean flag that
determines whether to return only the first node that matches the criteria specified by the
keyNodeEntryOrPredicate
parameter. If onlyOne
is set to true
, the function will
Optional
startNode: The startNode
parameter in the
getNodes
function is used to specify the starting point for traversing the binary tree. It
represents the root node of the binary tree or the node from which the traversal should begin. If
not provided, the default value is set to this._root @param {IterationType} iterationType - The
iterationTypeparameter in the
getNodesfunction determines the type of iteration to be performed when traversing the nodes of a binary tree. It can have two possible values: @returns The
getNodes` function returns an array of nodes that satisfy the provided condition
based on the input parameters and the iteration type specified.
Optional
iterationType: IterationTypeTime Complexity: O(log n) Space Complexity: O(log n)
The function getPathToRoot
in TypeScript retrieves the path from a given node to the root of a
tree structure, applying a specified callback function along the way.
The callback
parameter is a function that is used to process each node in
the path to the root. It is expected to be a function that takes a node as an argument and returns
a value based on that node. The return type of the callback function is determined by the generic
type C @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } beginNode - The
beginNodeparameter in the
getPathToRootfunction can be either a key, a node, an entry, or any other value of type
R. @param [isReverse=true] - The
isReverseparameter in the
getPathToRootfunction determines whether the resulting path from the given
beginNodeto the root should be in reverse order or not. If
isReverseis set to
true, the path will be reversed before being returned. If
is
Optional
isReverse: boolean = falseThe function getPathToRoot
returns an array of the return values of the callback
function callback
applied to each node in the path from the beginNode
to the root node. The
array is either in reverse order or in the original order based on the value of the isReverse
parameter.
Time Complexity: O(log n) Space Complexity: O(log n)
The function getPredecessor
in TypeScript returns the predecessor node of a given node in a
binary tree.
The getPredecessor
function you provided seems to be attempting to find the
predecessor of a given node in a binary tree. However, there seems to be a logical issue in the
while loop condition that might cause an infinite loop.
The getPredecessor
function returns the predecessor node of the input BinaryTreeNode<K, V>
parameter.
If the left child of the input node exists, it traverses to the rightmost node of the left subtree
to find the predecessor. If the left child does not exist, it returns the input node itself.
Time Complexity: O(log n) Space Complexity: O(log n)
The function getRightMost
retrieves the rightmost node in a binary tree using either recursive
or iterative traversal methods.
The callback
parameter is a function that will be called with the result
of finding the rightmost node in a binary tree. It is of type NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>
,
which means it is a callback function that can accept either an optional binary tree node or null
as
The startNode
parameter in the
getRightMost
function represents the starting point for finding the rightmost node in a binary
tree. It can be either a key, a node, or an entry in the binary tree structure. If no specific
starting point is provided, the function will default
The iterationType
parameter in the getRightMost
function specifies the type of iteration to be used when traversing the binary tree nodes. It can
have two possible values:
The getRightMost
function returns the result of the callback function C
, which is
passed as a parameter to the function. The callback function is called with the rightmost node in
the binary tree structure, determined based on the specified iteration type ('RECURSIVE' or
other).
Time Complexity: O(log n) Space Complexity: O(log n)
The function getSuccessor
in TypeScript returns the next node in an in-order traversal of a
binary tree.
Optional
x: null | K | BinaryTreeNode<K, V[]>The getSuccessor
function takes a parameter x
, which can be of
type K
, BinaryTreeNode<K, V>
, or null
.
The getSuccessor
function returns the successor node of the input node x
. If x
has
a right child, the function returns the leftmost node in the right subtree of x
. If x
does not
have a right child, the function traverses up the parent nodes until it finds a node that is not
the right child of its parent, and returns that node
Time Complexity: O(n) Space Complexity: O(1)
The function checks if a given key exists in a collection.
Optional
keyNodeEntryOrPredicate: Optional
startNode: Optional
iterationType: IterationTypea boolean value. It returns true if the key is found in the collection, and false otherwise.
Time Complexity: O(n) Space Complexity: O(1)
The function checks if a given value exists in a collection.
The parameter "value" is the value that we want to check if it exists in the collection.
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.
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.
a boolean value.
Time Complexity: O(n) Space Complexity: O(log n)
The function isBST
in TypeScript checks if a binary search tree is valid using either recursive
or iterative methods.
The startNode
parameter in the isBST
function represents the starting point for checking whether a binary search tree (BST) is valid.
It can be a node in the BST or a reference to the root of the BST. If no specific node is
provided, the function will default to
The iterationType
parameter in the isBST
function
determines whether the function should use a recursive approach or an iterative approach to check
if the binary search tree (BST) is valid.
The isBST
method is returning a boolean value, which indicates whether the binary
search tree (BST) represented by the given root node is a valid BST or not. The method checks if
the tree satisfies the BST property, where for every node, all nodes in its left subtree have keys
less than the node's key, and all nodes in its right subtree have keys greater than the node's
Time Complexity: O(1) Space Complexity: O(1)
The isEmpty
function in TypeScript checks if a data structure has no elements and returns a
boolean value.
The isEmpty()
method is returning a boolean value, specifically true
if the _size
property is equal to 0, indicating that the data structure is empty, and false
otherwise.
Time Complexity: O(1) Space Complexity: O(1)
The function isEntry
checks if the input is a BTNEntry object by verifying if it is an array
with a length of 2.
The keyNodeOrEntry
parameter in the isEntry
function can be of type K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined
or type R
.
The function checks if the provided keyNodeOrEntry
is of type BTN @returns The
isEntryfunction is checking if the
keyNodeOrEntryparameter is an array with a length of 2. If it is, then it returns
true, indicating that the parameter is of type
BTNEntry<K, V>. If the condition is not met, it returns
false`.
Time Complexity: O(1) Space Complexity: O(1)
The function determines whether a given key, node, entry, or raw data is a leaf node in a binary tree.
The parameter
keyNodeOrEntry
can be of type K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined
or R
. It represents a
key, node, entry, or raw data in a binary tree structure. The function isLeaf
checks whether the
provided
The function isLeaf
returns a boolean value indicating whether the input
keyNodeOrEntry
is a leaf node in a binary tree.
Time Complexity: O(1) Space Complexity: O(1)
The function isNIL checks if a given key, node, entry, or raw value is equal to the _NIL value.
The function is checking if the keyNodeOrEntry
parameter is equal to the _NIL
property of the current object and returning a boolean value based on that comparison.
Time Complexity: O(1) Space Complexity: O(1)
The function checks if the input is an instance of AVLTreeNode.
a boolean value indicating whether the input parameter keyNodeOrEntry
is
an instance of the AVLTreeNode
class.
Time Complexity: O(n) Space Complexity: O(log n)
The function checks if a binary tree is perfectly balanced by comparing its minimum height with its height.
The startNode
parameter is the starting
point for checking if the binary tree is perfectly balanced. It represents the root node of the
binary tree or a specific node from which the balance check should begin.
The method isPerfectlyBalanced
is returning a boolean value, which indicates whether
the tree starting from the startNode
node is perfectly balanced or not. The return value is
determined by comparing the minimum height of the tree with the height of the tree. If the minimum
height plus 1 is greater than or equal to the height of the tree, then it is considered perfectly
balanced and
Time Complexity: O(1) Space Complexity: O(1)
The function isRange
checks if the input parameter is an instance of the Range
class.
The keyNodeEntryOrPredicate
parameter in the isRange
function can be
of type K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined
, NodePredicate<BinaryTreeNode<K, V>>
, or
Range<K>
. The function checks if the keyNodeEntry @returns The
isRangefunction is checking if the
keyNodeEntryOrPredicateparameter is an instance of the
Rangeclass. If it is an instance of
Range, the function will return
true, indicating that the parameter is a
Range. If it is not an instance of
Range, the function will return
false`.
Time Complexity: O(1) Space Complexity: O(1)
The function isRaw
checks if the input parameter is of type R
by verifying if it is an object.
The function isRaw
is checking if the keyNodeEntryOrRaw
parameter is of type R
by
checking if it is an object. If the parameter is an object, the function will return true
,
indicating that it is of type R
.
Time Complexity: O(1) Space Complexity: O(1)
The function isRealNode
checks if a given input is a valid node in a binary tree.
The keyNodeOrEntry
parameter in the isRealNode
function can be of type K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined
or R
.
The function checks if the input parameter is a BinaryTreeNode<K, V>
type by verifying if it is not equal
The function isRealNode
is checking if the input keyNodeOrEntry
is a valid
node by comparing it to this._NIL
, null
, and undefined
. If the input is not one of these
values, it then calls the isNode
method to further determine if the input is a node. The
function will return a boolean value indicating whether the
Time Complexity: O(1) Space Complexity: O(1)
The function checks if a given input is a valid node or null.
The function isRealNodeOrNull
is returning a boolean value. It checks if the input
keyNodeOrEntry
is either null
or a real node, and returns true
if it is a node or
null
, and false
otherwise.
Time Complexity: O(1) Space Complexity: O(1)
The function "override isValidKey" checks if a key is comparable based on a given comparator.
The key
parameter is a value that will be checked to determine if it is of
type K
.
The override isValidKey(key: any): key is K
function is returning a boolean value based on
the result of the isComparable
function with the condition this._compare !== this._DEFAULT_COMPARATOR
.
Time complexity: O(n) Space complexity: O(n)
The leaves
function in TypeScript returns an array of values from leaf nodes in a binary tree
structure based on a specified callback and iteration type.
The callback
parameter is a function that will be called on each leaf node
in the binary tree. It is optional and defaults to a default callback function if not provided.
The startNode
parameter in the leaves
method is used to specify the starting point for finding and processing the leaves of a binary
tree. It can be provided as either a key, a node, or an entry in the binary tree structure. If not
explicitly provided, the default value
The iterationType
parameter in the leaves
method
specifies the type of iteration to be performed when collecting the leaves of a binary tree. It
can have two possible values:
The leaves
method returns an array of values that are the result of applying the
provided callback function to each leaf node in the binary tree.
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.
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.
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:
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,
The iterationType
parameter determines the type of
traversal to be performed on the binary tree. It can have two possible values:
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.
The callback
parameter is a generic type C
that extends
NodeCallback<BSTNode<K, V> | null>
. It represents a callback function that will be called for each node in the
tree during the iteration process.
The startNode
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
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:
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 in TypeScript overrides the default map behavior of an AVLTree data structure
by applying a callback function to each entry and creating a new AVLTree with the results.
A function that will be called for each entry in the AVLTree. It takes four arguments: the key, the value (which can be undefined), the index of the entry, and a reference to the AVLTree itself.
Optional
options: AVLTreeOptions<MK, MV[], MR>The options
parameter in the override map
function is of type
AVLTreeOptions<MK, MV, MR>
. It is an optional parameter that allows you to specify additional
options for the AVL tree being created during the mapping process. These options could include
custom comparators, initial
Optional
thisArg: anyThe thisArg
parameter in the override map
function is used to specify
the value of this
when executing the callback
function. It allows you to set the context
(value of this
) within the callback function. This can be useful when you want to access
properties or
The map
method is returning a new AVLTree instance (newTree
) with the entries
modified by the provided callback function.
Optional
callback: CThe callback
parameter in the morris
function is a function that will be
called on each node in the binary tree during the traversal. It is of type C
, which extends the
NodeCallback<BinaryTreeNode<K, V> | null>
type. The default value for callback
is this._DEFAULT @param {DFSOrderPattern} [pattern=IN] - The
patternparameter in the
morrisfunction specifies the type of Depth-First Search (DFS) order pattern to traverse the binary tree. The possible values for the
patternparameter are: @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The
startNodeparameter in the
morrisfunction is the starting point for the Morris traversal algorithm. It represents the root node of the binary tree or the node from which the traversal should begin. It can be provided as either a key, a node, an entry, or a reference @returns The
morris` function is returning an array of values that are the result of applying the
provided callback function to each node in the binary tree in the specified order pattern (IN,
PRE, or POST).
Optional
pattern: DFSOrderPatternOptional
startNode: 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
.
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.
The function perfectlyBalance
returns a boolean value.
Time Complexity: O(n) Space Complexity: O(n)
The function print
in TypeScript overrides the default print behavior to log a visual
representation of the binary tree to the console.
Optional
options: BinaryTreePrintOptionsThe options
parameter is used to specify the
printing options for the binary tree. It is an optional parameter that allows you to customize how
the binary tree is printed, such as choosing between different traversal orders or formatting
options.
The startNode
parameter in the
override print
method is used to specify the starting point for printing the binary tree. It can
be either a key, a node, an entry, or the root of the tree. If no specific starting point is
provided, the default value is set to
Time Complexity: O(log n) Space Complexity: O(k + log n)
The rangeSearch
function searches for nodes within a specified range in a binary search tree.
The range
parameter in the rangeSearch
function can be
either a Range
object or an array of two elements representing the range boundaries.
The callback
parameter in the rangeSearch
function is a callback
function that is used to process each node that is found within the specified range during the
search operation. It is of type NodeCallback<BSTNode<K, V> | null>
, where BSTNode<K, V>
is the type of nodes in the
data structure.
The startNode
parameter in the rangeSearch
function represents the node from which the search for nodes within the specified range will
begin. It is the starting point for the range search operation.
The iterationType
parameter in the rangeSearch
function
is used to specify the type of iteration to be performed during the search operation. It has a
default value of this.iterationType
, which suggests that it is likely a property of the class or
object that the rangeSearch
The rangeSearch
function is returning the result of calling the search
method with
the specified parameters.
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.
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.
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.
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 existing data structure and then adds new key-value pairs based
on the provided input.
The keysNodesEntriesOrRaws
parameter in the refill
method can accept an iterable containing a mix of K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined
objects or R
objects.
Optional
values: Iterable<undefined | V[], any, any>The values
parameter in the refill
method is an optional parameter that
accepts an iterable of values of type V
or undefined
.
Time Complexity: O(log n) Space Complexity: O(k + log n)
The function search
in TypeScript overrides the search behavior in a binary tree structure based
on specified criteria.
The
keyNodeEntryOrPredicate
parameter in the override search
method can accept one of the
following types:
Optional
onlyOne: boolean = falseThe onlyOne
parameter is a boolean flag that determines whether the
search should stop after finding the first matching node. If onlyOne
is set to true
, the
search will return as soon as a matching node is found. If onlyOne
is set to false
, the
The callback
parameter in the override search
function is a function
that will be called on each node that matches the search criteria. It is of type C
, which
extends NodeCallback<BSTNode<K, V> | null>
. The callback function should accept a node of type BSTNode<K, V>
as its
argument and
The startNode
parameter in the override search
method represents the node from which the search operation will begin. It is the starting point
for searching within the tree data structure. The method ensures that the startNode
is a valid
node before proceeding with the search operation. If the @param {IterationType} iterationType - The
iterationTypeparameter in the
override searchfunction determines the type of iteration to be used during the search operation. It can have two possible values: @returns The
override search` method returns an array of values that match the search criteria
specified by the input parameters. The method performs a search operation on a binary tree
structure based on the provided key, predicate, and other options. The search results are
collected in an array and returned as the output of the method.
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.
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: anyThe 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
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 toVisual
in TypeScript overrides the visual representation of a binary tree with
customizable options for displaying undefined, null, and sentinel nodes.
The startNode
parameter in the
toVisual
method is used to specify the starting point for visualizing the binary tree structure.
It can be a node, key, entry, or the root of the tree. If no specific starting point is provided,
the default is set to the root
Optional
options: BinaryTreePrintOptionsThe options
parameter in the toVisual
method is an
object that contains the following properties:
The override toVisual
method returns a string that represents the visual display of the
binary tree based on the provided options for showing undefined, null, and Red-Black NIL nodes.
The method constructs the visual representation by calling the _displayAux
method and appending
the lines to the output string. The final output string contains the visual representation of the
binary tree with the specified options.
The constructor initializes an AVLTreeMultiMap with the provided keys, nodes, entries, or raw data and options.