The constructor function initializes a binary tree object with optional keysOrNodesOrEntriesOrRawElements and options.
Optional
keysOrNodesOrEntriesOrRawElements: Iterable<R | KeyOrNodeOrEntry<K, V, NODE>> = []Optional iterable of KeyOrNodeOrEntry objects. These objects represent the nodes to be added to the binary tree.
Optional
options: BinaryTreeOptions<K, V, R>The options
parameter is an optional object that can contain additional
configuration options for the binary tree. In this case, it is of type
Partial<BinaryTreeOptions>
, which means that not all properties of BinaryTreeOptions
are
required.
The function returns the value of the _NIL property.
The method is returning the value of the _NIL
property.
The function returns the root node, which can be of type NODE, null, or undefined.
The method is returning the value of the _root
property, which can be of type NODE
,
null
, or undefined
.
The function returns the size of an object.
The size of the object, which is a number.
The function returns the value of the _toEntryFn property.
The function being returned is this._toEntryFn
.
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.
Protected
_displayTime 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.
The node
parameter represents a node in a binary tree.
It can be of type NODE
, null
, or undefined
.
The options
parameter is an object that contains the
following properties:
The function _displayAux
returns a NodeDisplayLayout
which is an array containing the
following elements:
mergedLines
: An array of strings representing the lines of the node display.totalWidth
: The total width of the node display.totalHeight
: The total height of the node display.middleIndex
: The index of the middle characterProtected
_ensureTime Complexity: O(1) Space Complexity: O(1)
The function _ensureCallback
ensures that a callback function is provided and returns it.
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
.
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.
the callback parameter.
Protected
_getTime 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.
The node
parameter represents the current node in the binary search tree. It is
initially set to the root node of the tree.
an IterableIterator<[K, V | undefined]>.
Protected
_replaceTime Complexity: O(1) Space Complexity: O(1)
The function replaces a node in a binary tree with a new node, updating the parent, left child, right child, and root if necessary.
The oldNode parameter represents the node that needs to be replaced in the tree.
The newNode
parameter is the node that will replace the oldNode
in the
tree.
the newNode.
Protected
_setTime Complexity: O(1) Space Complexity: O(1)
The function sets the root property of an object to the provided value, and also updates the parent property of the new root.
The parameter v
is of type NODE | null | undefined
. This
means that it can accept a value of type NODE
, null
, or undefined
.
Protected
_swapTime Complexity: O(1) Space Complexity: O(1)
The function _swapProperties
swaps the key-value properties between two nodes.
The source node that will be swapped with the
destination node. It can be either an instance of the class R
, or an object of type
KeyOrNodeOrEntry<K, V, NODE>
.
The destNode
parameter is the node where
the properties will be swapped with the srcNode
.
either the destNode
object with its properties swapped with the srcNode
object's
properties, or undefined
if either srcNode
or destNode
is falsy.
Time Complexity O(n) Space Complexity O(1)
The add
function is used to insert a new node into a binary tree, checking for duplicate keys
and finding the appropriate insertion position.
The
keyOrNodeOrEntryOrRawElement
parameter can accept a value of type R
, which represents the key,
node, entry, or raw element to be added to the tree. It can also accept a value of type
KeyOrNodeOrEntry<K, V, NODE> @param {V} [value] - The
valueparameter is an optional value that can be associated with the key being added to the tree. It represents the value that will be stored in the tree for the given key. @returns a boolean value. It returns
trueif the insertion is successful, and
false` if the
insertion position cannot be found or if there are duplicate keys.
Optional
value: VTime Complexity: O(k * n) Space Complexity: O(1)
The addMany
function takes in an iterable of keys or nodes or entries or raw elements, and an
optional iterable of values, and adds each key or node or entry with its corresponding value to a
data structure, returning an array of booleans indicating whether each insertion was successful.
An iterable containing keys, nodes, entries, or raw elements. These elements will be added to the data structure.
Optional
values: Iterable<undefined | V>An optional iterable of values that correspond to the keys or nodes or entries
in the keysOrNodesOrEntriesOrRawElements
parameter.
The function addMany
returns an array of booleans indicating whether each element was
successfully added to the data structure.
Time complexity: O(n) Space complexity: O(n)
The bfs
function performs a breadth-first search on a binary tree, calling a callback function
on each node and returning an array of the results.
Optional
callback: CThe callback
parameter is a function that will be called for each node in
the breadth-first search traversal. It takes a single argument, which is the current node being
visited, and returns a value of any type.
Optional
beginRoot: R | KeyOrNodeOrEntry<K, V, NODE>The beginRoot
parameter represents the
starting point of the breadth-first search. It can be either a root node of a tree or a key, node,
or entry object. If no value is provided, the root
property of the class is used as the default
starting point.
Optional
iterationType: IterationTypeThe iterationType
parameter determines the type of
iteration to be performed. It can have two possible values:
Optional
includeNull: falseThe includeNull
parameter is a boolean value that determines
whether or not to include null values in the breadth-first search (BFS) traversal. If
includeNull
is set to true
, null values will be included in the traversal. If includeNull
is
set to false @returns The function
bfsreturns an array of values that are the result of invoking the
callback` function on each node in the breadth-first order traversal of the binary tree.
Time complexity: O(n) Space complexity: O(n)
The bfs
function performs a breadth-first search on a binary tree, calling a callback function
on each node and returning an array of the results.
Optional
callback: CThe callback
parameter is a function that will be called for each node in
the breadth-first search traversal. It takes a single argument, which is the current node being
visited, and returns a value of any type.
Optional
beginRoot: R | KeyOrNodeOrEntry<K, V, NODE>The beginRoot
parameter represents the
starting point of the breadth-first search. It can be either a root node of a tree or a key, node,
or entry object. If no value is provided, the root
property of the class is used as the default
starting point.
Optional
iterationType: IterationTypeThe iterationType
parameter determines the type of
iteration to be performed. It can have two possible values:
Optional
includeNull: trueThe includeNull
parameter is a boolean value that determines
whether or not to include null values in the breadth-first search (BFS) traversal. If
includeNull
is set to true
, null values will be included in the traversal. If includeNull
is
set to false @returns The function
bfsreturns an array of values that are the result of invoking the
callback` function on each node in the breadth-first order traversal of the binary tree.
The function creates a binary tree with the given options.
Optional
options: Partial<BinaryTreeOptions<K, V, R>>The options
parameter is an optional object that allows you to customize the
behavior of the BinaryTree
class. It is of type Partial<BinaryTreeOptions>
, which means that
you can provide only a subset of the properties defined in the BinaryTreeOptions
interface.
a new instance of a binary tree.
Time Complexity: O(n) Space Complexity: O(1)
The above function is a TypeScript implementation of deleting a node from a binary tree, returning the deleted node and the node that needs to be balanced.
The identifier
parameter is the value
used to identify the node that needs to be deleted from the binary tree. It can be of any type
that is returned by the callback function.
Optional
callback: CThe callback
parameter is a function that is used to determine the
identifier of the node to be deleted. It is of type C
, which extends the BTNCallback<NODE>
interface. The BTNCallback<NODE>
interface represents a callback function that takes a node of
type NODE @returns an array of
BinaryTreeDeleteResult
Time Complexity: O(n) Space Complexity: O(1)
The above function is a TypeScript implementation of deleting a node from a binary tree, returning the deleted node and the node that needs to be balanced.
The identifier
parameter is the value
used to identify the node that needs to be deleted from the binary tree. It can be of any type
that is returned by the callback function.
Optional
callback: CThe callback
parameter is a function that is used to determine the
identifier of the node to be deleted. It is of type C
, which extends the BTNCallback<NODE>
interface. The BTNCallback<NODE>
interface represents a callback function that takes a node of
type NODE @returns an array of
BinaryTreeDeleteResult
Time Complexity: O(n) Space Complexity: O(1)
The above function is a TypeScript implementation of deleting a node from a binary tree, returning the deleted node and the node that needs to be balanced.
The identifier
parameter is the value
used to identify the node that needs to be deleted from the binary tree. It can be of any type
that is returned by the callback function.
The callback
parameter is a function that is used to determine the
identifier of the node to be deleted. It is of type C
, which extends the BTNCallback<NODE>
interface. The BTNCallback<NODE>
interface represents a callback function that takes a node of
type NODE @returns an array of
BinaryTreeDeleteResult
Time complexity: O(n) Space complexity: O(n)
The dfs
function performs a depth-first search traversal on a binary tree, executing a callback
function on each node according to a specified pattern and iteration type.
Optional
callback: CThe callback
parameter is a function that will be called for each node
visited during the depth-first search. It takes a node as an argument and returns a value. The
return type of the callback function is determined by the generic type C
.
Optional
pattern: DFSOrderPatternThe pattern
parameter determines the order in which the
nodes are visited during the depth-first search. It can have one of the following values:
Optional
beginRoot: R | KeyOrNodeOrEntry<K, V, NODE>The beginRoot
parameter is the starting
point of the depth-first search. It can be either a node object, a key-value pair, or a key. If it
is a key or key-value pair, the method will find the corresponding node in the tree and start the
search from there.
Optional
iterationType: IterationTypeThe iterationType
parameter determines the
type of iteration to use during the depth-first search. It can have two possible values:
Optional
includeNull: falseThe includeNull
parameter is a boolean value that determines
whether or not to include null values in the depth-first search traversal. If includeNull
is set
to true
, null values will be included in the traversal. If includeNull
is set to false
, null
values will
an array of the return types of the callback function.
Time complexity: O(n) Space complexity: O(n)
The dfs
function performs a depth-first search traversal on a binary tree, executing a callback
function on each node according to a specified pattern and iteration type.
Optional
callback: CThe callback
parameter is a function that will be called for each node
visited during the depth-first search. It takes a node as an argument and returns a value. The
return type of the callback function is determined by the generic type C
.
Optional
pattern: DFSOrderPatternThe pattern
parameter determines the order in which the
nodes are visited during the depth-first search. It can have one of the following values:
Optional
beginRoot: R | KeyOrNodeOrEntry<K, V, NODE>The beginRoot
parameter is the starting
point of the depth-first search. It can be either a node object, a key-value pair, or a key. If it
is a key or key-value pair, the method will find the corresponding node in the tree and start the
search from there.
Optional
iterationType: IterationTypeThe iterationType
parameter determines the
type of iteration to use during the depth-first search. It can have two possible values:
Optional
includeNull: trueThe includeNull
parameter is a boolean value that determines
whether or not to include null values in the depth-first search traversal. If includeNull
is set
to true
, null values will be included in the traversal. If includeNull
is set to false
, null
values will
an array of the return types of the callback function.
Time Complexity: O(n) Space Complexity: O(log n)
The ensureNode
function checks if the input is a valid node and returns it, or converts it to a
node if it is a key or entry.
The parameter
keyOrNodeOrEntryOrRawElement
can accept a value of type R
, KeyOrNodeOrEntry<K, V, NODE>
, or
a raw element.
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. It has a
default value of 'ITERATIVE'
.
The function ensureNode
returns either a NODE
object, null
, or undefined
.
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 creates a new tree with entries that pass a given predicate function.
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: anyThe 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
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.
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)
The function get
in TypeScript overrides the base class method and returns the value associated
with the given identifier.
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: CThe 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: IterationTypeThe 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:
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.
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: CThe 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: IterationTypeThe 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:
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.
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.
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: IterationTypeThe 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:
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.
The dist
parameter can be either a R
(representing a root node), or a KeyOrNodeOrEntry<K, V, NODE>
(representing a key, node, or
entry).
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
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.
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.
The iterationType
parameter determines the type of
iteration used to calculate the height of the tree. It can have two possible values:
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.
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
.
The iterationType
parameter is used to specify the type
of iteration to be performed. It can have two possible values:
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.
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.
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:
The function getMinHeight
returns a number, which represents the minimum height of the
binary tree.
Time Complexity: O(n) Space Complexity: O(log n).
The function getNode
returns the first node that matches the given identifier and callback,
starting from the specified root node and using the specified iteration type.
The identifier
parameter is the value
used to identify the node you want to retrieve. It can be of any type that is the return type of
the C
callback function, or it can be null
or undefined
.
Optional
callback: CThe callback
parameter is a function that will be used to determine if a
node matches the desired criteria. It should return a value that can be used to identify the node.
Optional
beginRoot: R | KeyOrNodeOrEntry<K, V, NODE>The beginRoot
parameter is the starting
point for searching nodes in a tree structure. It can be either a root node, a key-value pair, or
a node entry. If not provided, the search will start from the root of the tree.
Optional
iterationType: IterationTypeThe iterationType
parameter is used to specify the type
of iteration to be performed when searching for nodes. It can have one of the following values:
The method is returning a NODE object, or null, or undefined.
Time Complexity: O(n) Space Complexity: O(log n).
The function getNode
returns the first node that matches the given identifier and callback,
starting from the specified root node and using the specified iteration type.
The identifier
parameter is the value
used to identify the node you want to retrieve. It can be of any type that is the return type of
the C
callback function, or it can be null
or undefined
.
Optional
callback: CThe callback
parameter is a function that will be used to determine if a
node matches the desired criteria. It should return a value that can be used to identify the node.
Optional
beginRoot: R | KeyOrNodeOrEntry<K, V, NODE>The beginRoot
parameter is the starting
point for searching nodes in a tree structure. It can be either a root node, a key-value pair, or
a node entry. If not provided, the search will start from the root of the tree.
Optional
iterationType: IterationTypeThe iterationType
parameter is used to specify the type
of iteration to be performed when searching for nodes. It can have one of the following values:
The method is returning a NODE object, or null, or undefined.
Time Complexity: O(n) Space Complexity: O(log n).
The function getNode
returns the first node that matches the given identifier and callback,
starting from the specified root node and using the specified iteration type.
The identifier
parameter is the value
used to identify the node you want to retrieve. It can be of any type that is the return type of
the C
callback function, or it can be null
or undefined
.
The callback
parameter is a function that will be used to determine if a
node matches the desired criteria. It should return a value that can be used to identify the node.
Optional
beginRoot: R | KeyOrNodeOrEntry<K, V, NODE>The beginRoot
parameter is the starting
point for searching nodes in a tree structure. It can be either a root node, a key-value pair, or
a node entry. If not provided, the search will start from the root of the tree.
Optional
iterationType: IterationTypeThe iterationType
parameter is used to specify the type
of iteration to be performed when searching for nodes. It can have one of the following values:
The method is returning a NODE object, or null, or undefined.
Time Complexity: O(n) Space Complexity: O(log n)
The function getNodeByKey
returns a node with a specific key value from a tree structure.
The key parameter is the value that you want to search for in the tree. It is used to find the node with the matching key value.
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'
.
a value of type NODE, null, or undefined.
Time Complexity: O(n) Space Complexity: O(k + log n)
The function getNodes
returns an array of nodes that match a given identifier, using either a
recursive or iterative approach.
The identifier
parameter is the value
that is used to identify the nodes. It can be of any type and is used to match against the result
of the callback function for each node.
Optional
callback: CThe 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 a default callback function
(this._DEFAULT_CALLBACK
) if not provided.
Optional
onlyOne: booleanA boolean value indicating whether to return only one node that matches the identifier or all nodes that match the identifier. 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.
Optional
beginRoot: R | KeyOrNodeOrEntry<K, V, NODE>The beginRoot
parameter is the starting
point for the search. It can be either a node object, a key-value pair, or a key. If it is not
provided, the root
of the data structure is used as the starting point.
Optional
iterationType: IterationTypeThe iterationType
parameter determines the type of
iteration to be performed on the nodes of a binary tree. It can have two possible values:
an array of NODE objects.
Time Complexity: O(n) Space Complexity: O(k + log n)
The function getNodes
returns an array of nodes that match a given identifier, using either a
recursive or iterative approach.
The identifier
parameter is the value
that is used to identify the nodes. It can be of any type and is used to match against the result
of the callback function for each node.
Optional
callback: CThe 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 a default callback function
(this._DEFAULT_CALLBACK
) if not provided.
Optional
onlyOne: booleanA boolean value indicating whether to return only one node that matches the identifier or all nodes that match the identifier. 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.
Optional
beginRoot: R | KeyOrNodeOrEntry<K, V, NODE>The beginRoot
parameter is the starting
point for the search. It can be either a node object, a key-value pair, or a key. If it is not
provided, the root
of the data structure is used as the starting point.
Optional
iterationType: IterationTypeThe iterationType
parameter determines the type of
iteration to be performed on the nodes of a binary tree. It can have two possible values:
an array of NODE objects.
Time Complexity: O(n) Space Complexity: O(k + log n)
The function getNodes
returns an array of nodes that match a given identifier, using either a
recursive or iterative approach.
The identifier
parameter is the value
that is used to identify the nodes. It can be of any type and is used to match against the result
of the callback function for each node.
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 a default callback function
(this._DEFAULT_CALLBACK
) if not provided.
Optional
onlyOne: booleanA boolean value indicating whether to return only one node that matches the identifier or all nodes that match the identifier. 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.
Optional
beginRoot: R | KeyOrNodeOrEntry<K, V, NODE>The beginRoot
parameter is the starting
point for the search. It can be either a node object, a key-value pair, or a key. If it is not
provided, the root
of the data structure is used as the starting point.
Optional
iterationType: IterationTypeThe iterationType
parameter determines the type of
iteration to be performed on the nodes of a binary tree. It can have two possible values:
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.
The beginNode
parameter can be either of
type R
or KeyOrNodeOrEntry<K, V, NODE>
.
Optional
isReverse: boolean = trueThe 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
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.
The parameter "node" is of type "NODE", which represents a node in a binary tree.
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.
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
.
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:
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.
Optional
x: null | K | NODEThe parameter x
can be of type K
, NODE
, or null
.
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.
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: CThe 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: IterationTypeThe iterationType
parameter is used to specify the type
of iteration to be performed. It is an optional parameter with a default value of IterationType
.
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.
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: CThe 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: IterationTypeThe iterationType
parameter is used to specify the type
of iteration to be performed. It is an optional parameter with a default value of IterationType
.
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.
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.
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: IterationTypeThe iterationType
parameter is used to specify the type
of iteration to be performed. It is an optional parameter with a default value of IterationType
.
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.
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(1)
The function isBST
checks if a binary search tree is valid, either recursively or iteratively.
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
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:
a boolean value.
The function checks if the input is an array with two elements, indicating it is a binary tree node entry.
The parameter
keyOrNodeOrEntryOrRawElement
can be of type R
or KeyOrNodeOrEntry<K, V, NODE>
.
a boolean value.
The function checks if a given value is a valid key by evaluating its type and value.
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 = trueThe 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().
a boolean value.
The function checks if the input is an instance of the BinaryTreeNode class.
The parameter
keyOrNodeOrEntryOrRawElement
can be of type R
or KeyOrNodeOrEntry<K, V, NODE>
.
a boolean value indicating whether the input parameter keyOrNodeOrEntryOrRawElement
is
an instance of the BinaryTreeNode
class.
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.
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
a boolean value.
The function keyValueOrEntryOrRawElementToNode
converts a key-value pair, entry, or raw element
into a node object.
The parameter
keyOrNodeOrEntryOrRawElement
can be of type R
or KeyOrNodeOrEntry<K, V, NODE>
.
Optional
value: VThe value
parameter is an optional value that can be passed to the
keyValueOrEntryOrRawElementToNode
function. It represents the value associated with a key in a
key-value pair. If provided, it will be used to create a node with the specified key and value.
The function keyValueOrEntryOrRawElementToNode
returns either a NODE
object, null
,
or undefined
.
Time complexity: O(n) Space complexity: O(n)
The listLevels
function returns an array of arrays, where each inner array represents a level in
a binary tree and contains the results of applying a callback function to the nodes at that level.
Optional
callback: CThe callback
parameter is a function that will be called for each node in
the tree. It takes a node as an argument and returns a value. The return type of the callback
function is determined by the generic type C
which extends BTNCallback<NODE | null>
.
Optional
beginRoot: R | KeyOrNodeOrEntry<K, V, NODE>The beginRoot
parameter represents the
starting point for traversing the tree. It can be either a root node, a key-value pair, or a node
entry. If no value is provided, the root
property of the class is used as the default starting
point.
Optional
iterationType: IterationTypeThe iterationType
parameter determines the type of
iteration to be performed on the binary tree. It can have two possible values:
Optional
includeNull: falseThe includeNull
parameter is a boolean value that determines
whether or not to include null values in the resulting levels. If includeNull
is set to true
,
null values will be included in the levels. If includeNull
is set to false
, null values will
be excluded
The function listLevels
returns a two-dimensional array of type ReturnType<C>[][]
.
Time complexity: O(n) Space complexity: O(n)
The listLevels
function returns an array of arrays, where each inner array represents a level in
a binary tree and contains the results of applying a callback function to the nodes at that level.
Optional
callback: CThe callback
parameter is a function that will be called for each node in
the tree. It takes a node as an argument and returns a value. The return type of the callback
function is determined by the generic type C
which extends BTNCallback<NODE | null>
.
Optional
beginRoot: R | KeyOrNodeOrEntry<K, V, NODE>The beginRoot
parameter represents the
starting point for traversing the tree. It can be either a root node, a key-value pair, or a node
entry. If no value is provided, the root
property of the class is used as the default starting
point.
Optional
iterationType: IterationTypeThe iterationType
parameter determines the type of
iteration to be performed on the binary tree. It can have two possible values:
Optional
includeNull: trueThe includeNull
parameter is a boolean value that determines
whether or not to include null values in the resulting levels. If includeNull
is set to true
,
null values will be included in the levels. If includeNull
is set to false
, null values will
be excluded
The function listLevels
returns a two-dimensional array of type ReturnType<C>[][]
.
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.
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: anyThe 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
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.
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:
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.
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 print
function in TypeScript prints the binary tree structure with customizable options.
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: BinaryTreePrintOptionsThe options
parameter is an optional object that
allows you to customize the printing behavior. It has the following properties:
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.
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 current data and adds new data to the collection.
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
.
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.
Generated using TypeDoc