Class AVLTree<N>

Type Parameters

Hierarchy

Implements

Constructors

Properties

_comparator: BSTComparator = ...

Accessors

Methods

  • The BFS function performs a breadth-first search on a binary tree, accumulating properties of each node based on a specified property name.

    Returns number[]

    an instance of the AbstractBinaryTreeNodeProperties class with generic type N.

  • The BFS function performs a breadth-first search on a binary tree, accumulating properties of each node based on a specified property name.

    Parameters

    • nodeOrPropertyName: "id"

      The parameter nodeOrPropertyName is an optional parameter that represents either a node or a property name. If a node is provided, the breadth-first search (BFS) algorithm will be performed starting from that node. If a property name is provided, the BFS algorithm will be performed starting from the

    Returns number[]

    an instance of the AbstractBinaryTreeNodeProperties class with generic type N.

  • The BFS function performs a breadth-first search on a binary tree, accumulating properties of each node based on a specified property name.

    Parameters

    • nodeOrPropertyName: "val"

      The parameter nodeOrPropertyName is an optional parameter that represents either a node or a property name. If a node is provided, the breadth-first search (BFS) algorithm will be performed starting from that node. If a property name is provided, the BFS algorithm will be performed starting from the

    Returns N["val"][]

    an instance of the AbstractBinaryTreeNodeProperties class with generic type N.

  • The BFS function performs a breadth-first search on a binary tree, accumulating properties of each node based on a specified property name.

    Parameters

    • nodeOrPropertyName: "node"

      The parameter nodeOrPropertyName is an optional parameter that represents either a node or a property name. If a node is provided, the breadth-first search (BFS) algorithm will be performed starting from that node. If a property name is provided, the BFS algorithm will be performed starting from the

    Returns N[]

    an instance of the AbstractBinaryTreeNodeProperties class with generic type N.

  • The DFS function performs a depth-first search traversal on a binary tree and returns the accumulated properties of each node based on the specified pattern and property name.

    Returns number[]

    an instance of the AbstractBinaryTreeNodeProperties class, which contains the accumulated properties of the binary tree nodes based on the specified pattern and node or property name.

  • The DFS function performs a depth-first search traversal on a binary tree and returns the accumulated properties of each node based on the specified pattern and property name.

    Parameters

    • Optional pattern: DFSOrderPattern

      The "pattern" parameter is used to specify the traversal order of the binary tree. It can have three possible values:

    • Optional nodeOrPropertyName: "id"

      The nodeOrPropertyName parameter is a string that represents the name of a property of the nodes in the binary tree. This property will be used to accumulate values during the depth-first search traversal. If no nodeOrPropertyName is provided, the default value is 'id'.

    Returns number[]

    an instance of the AbstractBinaryTreeNodeProperties class, which contains the accumulated properties of the binary tree nodes based on the specified pattern and node or property name.

  • The DFS function performs a depth-first search traversal on a binary tree and returns the accumulated properties of each node based on the specified pattern and property name.

    Parameters

    • Optional pattern: DFSOrderPattern

      The "pattern" parameter is used to specify the traversal order of the binary tree. It can have three possible values:

    • Optional nodeOrPropertyName: "val"

      The nodeOrPropertyName parameter is a string that represents the name of a property of the nodes in the binary tree. This property will be used to accumulate values during the depth-first search traversal. If no nodeOrPropertyName is provided, the default value is 'id'.

    Returns N[]

    an instance of the AbstractBinaryTreeNodeProperties class, which contains the accumulated properties of the binary tree nodes based on the specified pattern and node or property name.

  • The DFS function performs a depth-first search traversal on a binary tree and returns the accumulated properties of each node based on the specified pattern and property name.

    Parameters

    • Optional pattern: DFSOrderPattern

      The "pattern" parameter is used to specify the traversal order of the binary tree. It can have three possible values:

    • Optional nodeOrPropertyName: "node"

      The nodeOrPropertyName parameter is a string that represents the name of a property of the nodes in the binary tree. This property will be used to accumulate values during the depth-first search traversal. If no nodeOrPropertyName is provided, the default value is 'id'.

    Returns N[]

    an instance of the AbstractBinaryTreeNodeProperties class, which contains the accumulated properties of the binary tree nodes based on the specified pattern and node or property name.

  • The DFSIterative function performs an iterative depth-first search traversal on a binary tree, with the option to specify the traversal pattern and the property name to accumulate results by.

    Returns number[]

    an object of type AbstractBinaryTreeNodeProperties.

  • The DFSIterative function performs an iterative depth-first search traversal on a binary tree, with the option to specify the traversal pattern and the property name to accumulate results by.

    Parameters

    • Optional pattern: DFSOrderPattern

      The "pattern" parameter determines the order in which the nodes of the binary tree are visited during the depth-first search. It can have one of the following values:

    • Optional nodeOrPropertyName: "id"

      The nodeOrPropertyName parameter is used to specify the property of the nodes that you want to retrieve or perform operations on during the depth-first search traversal. By default, it is set to 'id', which means that the traversal will accumulate results based on the id property of the

    Returns number[]

    an object of type AbstractBinaryTreeNodeProperties.

  • The DFSIterative function performs an iterative depth-first search traversal on a binary tree, with the option to specify the traversal pattern and the property name to accumulate results by.

    Parameters

    • Optional pattern: DFSOrderPattern

      The "pattern" parameter determines the order in which the nodes of the binary tree are visited during the depth-first search. It can have one of the following values:

    • Optional nodeOrPropertyName: "val"

      The nodeOrPropertyName parameter is used to specify the property of the nodes that you want to retrieve or perform operations on during the depth-first search traversal. By default, it is set to 'id', which means that the traversal will accumulate results based on the id property of the

    Returns N[]

    an object of type AbstractBinaryTreeNodeProperties.

  • The DFSIterative function performs an iterative depth-first search traversal on a binary tree, with the option to specify the traversal pattern and the property name to accumulate results by.

    Parameters

    • Optional pattern: DFSOrderPattern

      The "pattern" parameter determines the order in which the nodes of the binary tree are visited during the depth-first search. It can have one of the following values:

    • Optional nodeOrPropertyName: "node"

      The nodeOrPropertyName parameter is used to specify the property of the nodes that you want to retrieve or perform operations on during the depth-first search traversal. By default, it is set to 'id', which means that the traversal will accumulate results based on the id property of the

    Returns N[]

    an object of type AbstractBinaryTreeNodeProperties.

  • The function _accumulatedByPropertyName accumulates values from a given node based on the specified property name.

    Parameters

    • node: N

      The node parameter is of type N, which represents a node in a data structure.

    • Optional nodeOrPropertyName: NodeOrPropertyName

      The nodeOrPropertyName parameter is an optional parameter that can be either a string representing a property name or a reference to a Node object. If it is a string, it specifies the property name to be used for accumulating values. If it is a Node object, it specifies

    Returns void

  • The function adds a new node to a binary tree if there is an available position.

    Parameters

    • newNode: null | N

      The newNode parameter is of type N | null, which means it can either be a node of type N or null. It represents the node that you want to add to the binary tree.

    • parent: N

      The parent parameter is of type N, which represents a node in a binary tree.

    Returns undefined | null | N

    either the left or right child node of the parent node, depending on which child is available for adding the new node. If a new node is added, the function also updates the size of the binary tree. If neither the left nor right child is available, the function returns undefined. If the parent node is null, the function also returns undefined.

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

    Parameters

    • node: N

      The parameter "node" is of type N, which represents a node in an AVL tree.

    Returns number

    The balance factor of the given AVL tree node.

  • The _balancePath function balances the AVL tree by performing appropriate rotations based on the balance factor of each node in the path from the given node to the root.

    Parameters

    • node: N

      The node parameter is an AVLTreeNode object, which represents a node in an AVL tree.

    Returns void

  • The _balanceRR function performs a right-right rotation on an AVL tree to balance it.

    Parameters

    • A: N

      The parameter A is an AVLTreeNode object.

    Returns void

  • The function compares two binary tree node IDs using a comparator function and returns whether the first ID is greater than, less than, or equal to the second ID.

    Parameters

    • a: number

      a is a BinaryTreeNodeId, which represents the identifier of a binary tree node.

    • b: number

      The parameter "b" in the above code refers to a BinaryTreeNodeId.

    Returns CP

    a value of type CP (ComparisonResult). The possible return values are CP.gt (greater than), CP.lt (less than), or CP.eq (equal).

  • The function checks if a given property of a binary tree node matches a specified value, and if so, adds the node to a result array.

    Parameters

    • cur: N

      The current node being processed.

    • result: (undefined | null | N)[]

      An array that stores the matching nodes.

    • nodeProperty: number | N

      The nodeProperty parameter is either a BinaryTreeNodeId or a N type. It represents the property value that we are comparing against in the switch statement.

    • Optional propertyName: BinaryTreeNodePropertyName

      The propertyName parameter is an optional parameter that specifies the property name to compare against when pushing nodes into the result array. It can be either 'id' or 'val'. If it is not provided or is not equal to 'id' or 'val', the

    • Optional onlyOne: boolean

      The onlyOne parameter is an optional boolean parameter that determines whether to stop after finding the first matching node or continue searching for all matching nodes. If onlyOne is set to true, the function will stop after finding the first matching node and return true. If `onlyOne

    Returns undefined | boolean

    a boolean value indicating whether only one matching node should be pushed into the result array.

  • The function sets the root property of an object to a given value, and if the value is not null, it also sets the parent property of the value to undefined.

    Parameters

    • v: null | N

      The parameter v is of type N | null, which means it can either be of type N or null.

    Returns void

  • The function updates the height of a node in an AVL tree based on the heights of its left and right subtrees.

    Parameters

    • node: N

      The parameter node is an AVLTreeNode object, which represents a node in an AVL tree.

    Returns void

  • The function overrides the add method of a binary tree node and balances the tree after inserting a new node.

    Parameters

    • id: number

      The id parameter is the identifier of the binary tree node that we want to add.

    • Optional val: N["val"]

      The val parameter is an optional value that can be assigned to the node being added. It is of type N['val'], which means it should be of the same type as the val property of the nodes in the binary tree.

    Returns undefined | null | N

    The method is returning the inserted node, or null or undefined if the insertion was not successful.

  • The addMany function overrides the base class method to add multiple nodes to a binary search tree in a balanced manner.

    Parameters

    • idsOrNodes: (null | number)[] | (null | N)[]

      The idsOrNodes parameter in the addMany function is an array of BinaryTreeNodeId or N (node) objects, or null values. It represents the nodes or node IDs that need to be added to the binary search tree.

    • Optional data: N["val"][]

      The values of tree nodes

    • isBalanceAdd: boolean = false

      If true the nodes will be balance inserted in binary search method.

    Returns (undefined | null | N)[]

    The function addMany returns an array of N, null, or undefined values.

  • The allGreaterNodesAdd function adds a delta value to the specified property of all nodes in a binary tree that have a greater value than a given node.

    Parameters

    • node: null | number | N

      The node parameter can be either of type N (a generic type), BinaryTreeNodeId, or null. It represents the node in the binary tree to which the delta value will be added.

    • delta: number

      The delta parameter is a number that represents the amount by which the property value of each greater node should be increased.

    • Optional propertyName: BinaryTreeNodePropertyName

      The propertyName parameter is an optional parameter that specifies the property name of the nodes in the binary tree that you want to update. If not provided, it defaults to 'id'.

    Returns boolean

    a boolean value.

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

    Parameters

    • id: number

      The id parameter is the identifier for the binary tree node. It is used to uniquely identify each node in the tree.

    • Optional val: N["val"]

      The val parameter is an optional value that can be assigned to the node. It represents the value that will be stored in the node.

    Returns N

    a new AVLTreeNode object with the specified id and value.

  • The fill function clears the binary tree and adds multiple nodes with the given IDs or nodes and optional data.

    Parameters

    • idsOrNodes: (null | number)[] | (null | N)[]

      The idsOrNodes parameter is an array that can contain either BinaryTreeNodeId or N values.

    • Optional data: N[] | N["val"][]

      The data parameter is an optional array of values that will be assigned to the nodes being added. If provided, the length of the data array should be equal to the length of the idsOrNodes array. Each value in the data array will be assigned to the

    Returns boolean

    The method is returning a boolean value.

  • The function returns the first node in a binary tree that matches the given property name and value.

    Parameters

    • nodeProperty: number | N

      The nodeProperty parameter can be either a BinaryTreeNodeId or a generic type N. It represents the property of the binary tree node that you want to search for.

    • Optional propertyName: BinaryTreeNodePropertyName

      The propertyName parameter is an optional parameter that specifies the property name to use for searching the binary tree nodes. If not provided, it defaults to 'id'.

    Returns null | N

    The method is returning either a BinaryTreeNodeId or N (generic type) or null.

  • The getHeight function calculates the maximum height of a binary tree, either recursively or iteratively.

    Parameters

    • Optional beginRoot: null | number | N

      The beginRoot parameter is optional and can be of type N (a generic type representing a node in a binary tree), BinaryTreeNodeId (a type representing the ID of a binary tree node), or null.

    Returns number

    the height of the binary tree.

  • The getLeftMost function returns the leftmost node in a binary tree, starting from a specified node or the root if no node is specified.

    Returns null | N

    The function getLeftMost returns the leftmost node in a binary tree. If the beginRoot parameter is provided, it starts the traversal from that node. If beginRoot is not provided or is null, it starts the traversal from the root of the binary tree. If there are no nodes in the binary tree, it returns null.

  • The getLeftMost function returns the leftmost node in a binary tree, starting from a specified node or the root if no node is specified.

    Parameters

    • node: N

    Returns N

    The function getLeftMost returns the leftmost node in a binary tree. If the beginRoot parameter is provided, it starts the traversal from that node. If beginRoot is not provided or is null, it starts the traversal from the root of the binary tree. If there are no nodes in the binary tree, it returns null.

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

    Parameters

    • Optional beginRoot: null | N

      The beginRoot parameter is an optional parameter of type N or null. It represents the starting node from which to calculate the minimum height of a binary tree. If no value is provided for beginRoot, the this.root property is used as the default value.

    Returns number

    The function getMinHeight returns the minimum height of the binary tree.

  • The function getNodes returns an array of nodes in a binary tree that match a given property value.

    Parameters

    • nodeProperty: number | N

      The nodeProperty parameter can be either a BinaryTreeNodeId or an N type. It represents the property of the binary tree node that you want to compare with.

    • Optional propertyName: BinaryTreeNodePropertyName = 'id'

      The propertyName parameter is an optional parameter that specifies the property name to use for comparison. If not provided, it defaults to 'id'.

    • Optional onlyOne: boolean

      The onlyOne parameter is an optional boolean parameter that determines whether to return only one node that matches the given nodeProperty or all nodes that match the nodeProperty. If onlyOne is set to true, the function will return an array with only one node (if

    Returns N[]

    an array of nodes (type N).

  • The function getPathToRoot returns an array of nodes representing the path from a given node to the root node, with an option to reverse the order of the nodes.

    Parameters

    • node: N

      The node parameter represents a node in a tree structure. It is of type N, which could be any type that represents a node in your specific implementation.

    • Optional isReverse: boolean = true

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

    Returns N[]

    The function getPathToRoot returns an array of nodes (N[]).

  • The getRightMost function returns the rightmost node in a binary tree, either recursively or iteratively using tail recursion optimization.

    Returns null | N

    The function getRightMost returns the rightmost node (N) in a binary tree. If the node parameter is not provided, it defaults to the root node of the tree. If the tree is empty or the node parameter is null, the function returns null.

  • The getRightMost function returns the rightmost node in a binary tree, either recursively or iteratively using tail recursion optimization.

    Parameters

    • node: N

      The node parameter is an optional parameter of type N or null. It represents the starting node from which we want to find the rightmost node. If no node is provided, the node parameter defaults to this.root, which is the root node of the data structure

    Returns N

    The function getRightMost returns the rightmost node (N) in a binary tree. If the node parameter is not provided, it defaults to the root node of the tree. If the tree is empty or the node parameter is null, the function returns null.

  • The function checks if a binary tree node has a specific property.

    Parameters

    • nodeProperty: number | N

      The nodeProperty parameter can be either a BinaryTreeNodeId or N. It represents the property of the binary tree node that you want to check.

    • Optional propertyName: BinaryTreeNodePropertyName

      The propertyName parameter is an optional parameter that specifies the name of the property to be checked in the nodes. If not provided, it defaults to 'id'.

    Returns boolean

    a boolean value.

  • The function returns the id of the rightmost node if the comparison between two values is less than, the id of the leftmost node if the comparison is greater than, and the id of the rightmost node otherwise.

    Returns number

    The method lastKey() returns the id of the rightmost node in the binary tree if the comparison between the values at index 0 and 1 is less than, otherwise it returns the id of the leftmost node. If the comparison is equal, it returns the id of the rightmost node. If there are no nodes in the tree, it returns 0.

  • The lesserSum function calculates the sum of property values in a binary tree for nodes that have a property value less than a given node.

    Parameters

    • beginNode: null | number | N

      The beginNode parameter can be one of the following:

    • Optional propertyName: BinaryTreeNodePropertyName

      The propertyName parameter is an optional parameter that specifies the property name to use for calculating the sum. If not provided, it defaults to 'id'.

    Returns number

    The function lesserSum returns a number, which represents the sum of the values of the nodes in the binary tree that have a lesser value than the specified beginNode based on the propertyName.

  • The levelIterative function performs a level-order traversal on a binary tree and returns the values of the nodes in an array, based on a specified property name.

    Parameters

    • node: null | N

      The node parameter is a BinaryTreeNode object representing the starting node for the level order traversal. It can be null if no specific node is provided, in which case the root node of the tree is used as the starting node.

    Returns number[]

    The function levelIterative returns an object of type AbstractBinaryTreeNodeProperties<N>.

  • The levelIterative function performs a level-order traversal on a binary tree and returns the values of the nodes in an array, based on a specified property name.

    Parameters

    • node: null | N

      The node parameter is a BinaryTreeNode object representing the starting node for the level order traversal. It can be null if no specific node is provided, in which case the root node of the tree is used as the starting node.

    • Optional nodeOrPropertyName: "id"

      The nodeOrPropertyName parameter is an optional parameter that can be either a BinaryTreeNode property name or the string 'id'. If a property name is provided, the function will accumulate results based on that property. If no property name is provided, the function will default to accumulating results

    Returns number[]

    The function levelIterative returns an object of type AbstractBinaryTreeNodeProperties<N>.

  • The levelIterative function performs a level-order traversal on a binary tree and returns the values of the nodes in an array, based on a specified property name.

    Parameters

    • node: null | N

      The node parameter is a BinaryTreeNode object representing the starting node for the level order traversal. It can be null if no specific node is provided, in which case the root node of the tree is used as the starting node.

    • Optional nodeOrPropertyName: "val"

      The nodeOrPropertyName parameter is an optional parameter that can be either a BinaryTreeNode property name or the string 'id'. If a property name is provided, the function will accumulate results based on that property. If no property name is provided, the function will default to accumulating results

    Returns N["val"][]

    The function levelIterative returns an object of type AbstractBinaryTreeNodeProperties<N>.

  • The levelIterative function performs a level-order traversal on a binary tree and returns the values of the nodes in an array, based on a specified property name.

    Parameters

    • node: null | N

      The node parameter is a BinaryTreeNode object representing the starting node for the level order traversal. It can be null if no specific node is provided, in which case the root node of the tree is used as the starting node.

    • Optional nodeOrPropertyName: "node"

      The nodeOrPropertyName parameter is an optional parameter that can be either a BinaryTreeNode property name or the string 'id'. If a property name is provided, the function will accumulate results based on that property. If no property name is provided, the function will default to accumulating results

    Returns N[]

    The function levelIterative returns an object of type AbstractBinaryTreeNodeProperties<N>.

  • The listLevels function collects nodes from a binary tree by a specified property and organizes them into levels.

    Parameters

    • node: null | N

      The node parameter is a BinaryTreeNode object or null. It represents the root node of a binary tree. If it is null, the function will use the root node of the current binary tree instance.

    Returns number[][]

    The function listLevels returns a 2D array of AbstractBinaryTreeNodeProperty<N> objects.

  • The listLevels function collects nodes from a binary tree by a specified property and organizes them into levels.

    Parameters

    • node: null | N

      The node parameter is a BinaryTreeNode object or null. It represents the root node of a binary tree. If it is null, the function will use the root node of the current binary tree instance.

    • Optional nodeOrPropertyName: "id"

      The nodeOrPropertyName parameter is an optional parameter that specifies the property of the BinaryTreeNode object to collect at each level. It can be one of the following values:

    Returns number[][]

    The function listLevels returns a 2D array of AbstractBinaryTreeNodeProperty<N> objects.

  • The listLevels function collects nodes from a binary tree by a specified property and organizes them into levels.

    Parameters

    • node: null | N

      The node parameter is a BinaryTreeNode object or null. It represents the root node of a binary tree. If it is null, the function will use the root node of the current binary tree instance.

    • Optional nodeOrPropertyName: "val"

      The nodeOrPropertyName parameter is an optional parameter that specifies the property of the BinaryTreeNode object to collect at each level. It can be one of the following values:

    Returns N["val"][][]

    The function listLevels returns a 2D array of AbstractBinaryTreeNodeProperty<N> objects.

  • The listLevels function collects nodes from a binary tree by a specified property and organizes them into levels.

    Parameters

    • node: null | N

      The node parameter is a BinaryTreeNode object or null. It represents the root node of a binary tree. If it is null, the function will use the root node of the current binary tree instance.

    • Optional nodeOrPropertyName: "node"

      The nodeOrPropertyName parameter is an optional parameter that specifies the property of the BinaryTreeNode object to collect at each level. It can be one of the following values:

    Returns N[][]

    The function listLevels returns a 2D array of AbstractBinaryTreeNodeProperty<N> objects.

  • The morris function performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm.

    Returns number[]

    an array of AbstractBinaryTreeNodeProperties objects.

  • The morris function performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm.

    Parameters

    • Optional pattern: DFSOrderPattern

      The pattern parameter determines the traversal pattern for the binary tree. It can have one of three values:

    • Optional nodeOrPropertyName: "id"

      The nodeOrPropertyName parameter is used to specify the property name of the nodes that you want to retrieve. It can be any valid property name of the nodes in the binary tree.

    Returns number[]

    an array of AbstractBinaryTreeNodeProperties objects.

  • The morris function performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm.

    Parameters

    • Optional pattern: DFSOrderPattern

      The pattern parameter determines the traversal pattern for the binary tree. It can have one of three values:

    • Optional nodeOrPropertyName: "val"

      The nodeOrPropertyName parameter is used to specify the property name of the nodes that you want to retrieve. It can be any valid property name of the nodes in the binary tree.

    Returns N[]

    an array of AbstractBinaryTreeNodeProperties objects.

  • Time complexity is O(n) Space complexity of Iterative DFS equals to recursive DFS which is O(n) because of the stack

    Parameters

    Returns N[]

  • The perfectlyBalance function takes a binary tree, performs a depth-first search to sort the nodes, and then constructs a balanced binary search tree using either a recursive or iterative approach.

    Returns boolean

    The function perfectlyBalance() returns a boolean value.

  • The function overrides the remove method of the Binary Search Tree class, performs the removal operation, and then balances the tree if necessary.

    Parameters

    • id: number

      The id parameter represents the identifier of the binary tree node that needs to be removed from the AVL tree.

    • Optional isUpdateAllLeftSum: boolean

      The isUpdateAllLeftSum parameter is an optional boolean parameter that determines whether the left sum of all nodes in the AVL tree should be updated after removing a node. If isUpdateAllLeftSum is set to true, the left sum of all nodes will be recalculated.

    Returns BinaryTreeDeletedResult<N>[]

    The method is returning an array of AVLTreeDeleted<N> objects.

  • The function subTreeAdd adds a delta value to a specified property of each node in a subtree.

    Parameters

    • subTreeRoot: null | number | N

      The subTreeRoot parameter represents the root node of a binary tree or the ID of a node in the binary tree. It can also be null if there is no subtree to add to.

    • delta: number

      The delta parameter is a number that represents the amount by which the property value of each node in the subtree should be incremented.

    • Optional propertyName: BinaryTreeNodePropertyName

      The propertyName parameter is an optional parameter that specifies the property of the binary tree node that should be modified. If not provided, it defaults to 'id'.

    Returns boolean

    a boolean value.

  • The function subTreeSum calculates the sum of a specified property in a binary tree or subtree.

    Parameters

    • subTreeRoot: null | number | N

      The subTreeRoot parameter represents the root node of a binary tree or the ID of a binary tree node. It can also be null if there is no subtree.

    • Optional propertyName: BinaryTreeNodePropertyName

      propertyName is an optional parameter that specifies the property of the binary tree node to use for calculating the sum. It can be either 'id' or 'val'. If propertyName is not provided, it defaults to 'id'.

    Returns number

    a number, which is the sum of the values of the specified property in the subtree rooted at subTreeRoot.

  • The swapLocation function swaps the location of two nodes in a binary tree.

    Parameters

    • srcNode: N

      The source node that you want to swap with the destination node.

    • destNode: N

      The destNode parameter represents the destination node where the values from srcNode will be swapped to.

    Returns N

    The destNode is being returned.

Generated using TypeDoc