# Class BinaryTree<N>

#### Type Parameters

- #### N extends BinaryTreeNode<N["val"], N> = BinaryTreeNode

#### Hierarchy

- AbstractBinaryTree<N>
  - BinaryTree
    - BST

#### Implements

- IBinaryTree<N>

- Defined in src/data-structures/binary-tree/binary-tree.ts:22

#####
Index

### Constructors

constructor

### Accessors

loopType
root
size
visitedId
visitedNode
visitedVal

### Methods

BFS
DFS
DFSIterative
_accumulatedByPropertyName
_addTo
_clearResults
_getResultByPropertyName
_pushByPropertyNameStopOrNot
_setLoopType
_setRoot
_setSize
_setVisitedId
_setVisitedNode
_setVisitedVal
add
addMany
clear
createNode
fill
get
getDepth
getHeight
getLeftMost
getMinHeight
getNodes
getPathToRoot
getPredecessor
getRightMost
getSubTreeSize
has
isBST
isEmpty
isPerfectlyBalanced
isSubtreeBST
levelIterative
listLevels
morris
remove
subTreeAdd
subTreeSum
swapLocation

## Constructors

### constructor

- new BinaryTree<N>(options?): BinaryTree<N>

- This is a constructor function for a binary tree class that takes an optional options parameter.

  #### Type Parameters

  - #### N extends BinaryTreeNode<N["val"], N, N> = BinaryTreeNode<any, BinaryTreeNodeNested<any>>

  #### Parameters

  - ##### `Optional` options: AbstractBinaryTreeOptions

    The `options` parameter is an optional object that can be passed to the constructor of the `BinaryTree` class. It allows you to customize the behavior of the binary tree by providing different configuration options.

  #### Returns BinaryTree<N>

  Overrides AbstractBinaryTree.constructor

  - Defined in src/data-structures/binary-tree/binary-tree.ts:32

## Accessors

### loopType

- get loopType(): LoopType

- #### Returns LoopType

  Implementation of IBinaryTree.loopType

  Inherited from AbstractBinaryTree.loopType

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:168

### root

- get root(): null | N

- #### Returns null | N

  Implementation of IBinaryTree.root

  Inherited from AbstractBinaryTree.root

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:156

### size

- get size(): number

- #### Returns number

  Implementation of IBinaryTree.size

  Inherited from AbstractBinaryTree.size

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:162

### visitedId

- get visitedId(): number[]

- #### Returns number[]

  Implementation of IBinaryTree.visitedId

  Inherited from AbstractBinaryTree.visitedId

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:174

### visitedNode

- get visitedNode(): N[]

- #### Returns N[]

  Implementation of IBinaryTree.visitedNode

  Inherited from AbstractBinaryTree.visitedNode

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:186

### visitedVal

- get visitedVal(): N["val"][]

- #### Returns N["val"][]

  Implementation of IBinaryTree.visitedVal

  Inherited from AbstractBinaryTree.visitedVal

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:180

## Methods

### BFS

- BFS(): number[]

- Performs a breadth-first search (BFS) on a binary tree, accumulating properties of each node based on their 'id' property.

  #### Returns number[]

  An array of binary tree node IDs.

  Implementation of IBinaryTree.BFS

  Inherited from AbstractBinaryTree.BFS

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:915
- BFS(nodeOrPropertyName): number[]

- Performs a breadth-first search (BFS) on a binary tree, accumulating properties of each node based on the specified property name.

  #### Parameters

  - ##### nodeOrPropertyName: "id"

    The name of the property to accumulate.

  #### Returns number[]

  An array of values corresponding to the specified property.

  Implementation of IBinaryTree.BFS

  Inherited from AbstractBinaryTree.BFS

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:922
- BFS(nodeOrPropertyName): N["val"][]

- Performs a breadth-first search (BFS) on a binary tree, accumulating the 'val' property of each node.

  #### Parameters

  - ##### nodeOrPropertyName: "val"

    The name of the property to accumulate.

  #### Returns N["val"][]

  An array of 'val' properties from each node.

  Implementation of IBinaryTree.BFS

  Inherited from AbstractBinaryTree.BFS

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:929
- BFS(nodeOrPropertyName): N[]

- Performs a breadth-first search (BFS) on a binary tree, accumulating nodes themselves.

  #### Parameters

  - ##### nodeOrPropertyName: "node"

    The name of the property to accumulate.

  #### Returns N[]

  An array of binary tree nodes.

  Implementation of IBinaryTree.BFS

  Inherited from AbstractBinaryTree.BFS

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:936

### DFS

- DFS(): number[]

- Performs a depth-first search (DFS) traversal on a binary tree and accumulates properties of each node based on their 'id' property.

  #### Returns number[]

  An array of binary tree node IDs.

  Implementation of IBinaryTree.DFS

  Inherited from AbstractBinaryTree.DFS

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:966
- DFS(pattern?, nodeOrPropertyName?): number[]

- Performs a depth-first search (DFS) traversal on a binary tree and accumulates properties of each node based on the specified property name.

  #### Parameters

  - ##### `Optional` pattern: DFSOrderPattern

    The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).

  - ##### `Optional` nodeOrPropertyName: "id"

    The name of the property to accumulate.

  #### Returns number[]

  An array of values corresponding to the specified property.

  Implementation of IBinaryTree.DFS

  Inherited from AbstractBinaryTree.DFS

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:974
- DFS(pattern?, nodeOrPropertyName?): N[]

- Performs a depth-first search (DFS) traversal on a binary tree and accumulates the 'val' property of each node.

  #### Parameters

  - ##### `Optional` pattern: DFSOrderPattern

    The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).

  - ##### `Optional` nodeOrPropertyName: "val"

    The name of the property to accumulate.

  #### Returns N[]

  An array of 'val' properties from each node.

  Implementation of IBinaryTree.DFS

  Inherited from AbstractBinaryTree.DFS

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:982
- DFS(pattern?, nodeOrPropertyName?): N[]

- Performs a depth-first search (DFS) traversal on a binary tree and accumulates nodes themselves.

  #### Parameters

  - ##### `Optional` pattern: DFSOrderPattern

    The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).

  - ##### `Optional` nodeOrPropertyName: "node"

    The name of the property to accumulate.

  #### Returns N[]

  An array of binary tree nodes.

  Implementation of IBinaryTree.DFS

  Inherited from AbstractBinaryTree.DFS

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:990

### DFSIterative

- DFSIterative(): number[]

- Performs an iterative depth-first search (DFS) traversal on a binary tree and accumulates properties of each node based on their 'id' property.

  #### Returns number[]

  An array of binary tree node IDs.

  Implementation of IBinaryTree.DFSIterative

  Inherited from AbstractBinaryTree.DFSIterative

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:1033
- DFSIterative(pattern?, nodeOrPropertyName?): number[]

- Performs an iterative depth-first search (DFS) traversal on a binary tree and accumulates properties of each node based on the specified property name.

  #### Parameters

  - ##### `Optional` pattern: DFSOrderPattern

    The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).

  - ##### `Optional` nodeOrPropertyName: "id"

    The name of the property to accumulate.

  #### Returns number[]

  An array of values corresponding to the specified property.

  Implementation of IBinaryTree.DFSIterative

  Inherited from AbstractBinaryTree.DFSIterative

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:1041
- DFSIterative(pattern?, nodeOrPropertyName?): N[]

- Performs an iterative depth-first search (DFS) traversal on a binary tree and accumulates the 'val' property of each node.

  #### Parameters

  - ##### `Optional` pattern: DFSOrderPattern

    The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).

  - ##### `Optional` nodeOrPropertyName: "val"

    The name of the property to accumulate.

  #### Returns N[]

  An array of 'val' properties from each node.

  Implementation of IBinaryTree.DFSIterative

  Inherited from AbstractBinaryTree.DFSIterative

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:1049
- DFSIterative(pattern?, nodeOrPropertyName?): N[]

- Performs an iterative depth-first search (DFS) traversal on a binary tree and accumulates nodes themselves.

  #### Parameters

  - ##### `Optional` pattern: DFSOrderPattern

    The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).

  - ##### `Optional` nodeOrPropertyName: "node"

    The name of the property to accumulate.

  #### Returns N[]

  An array of binary tree nodes.

  Implementation of IBinaryTree.DFSIterative

  Inherited from AbstractBinaryTree.DFSIterative

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:1057

### `Protected` _accumulatedByPropertyName

- _accumulatedByPropertyName(node, nodeOrPropertyName?): void

- 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

  Inherited from AbstractBinaryTree._accumulatedByPropertyName

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:1561

### `Protected` _addTo

- _addTo(newNode, parent): undefined | null | N

- 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.

  Inherited from AbstractBinaryTree._addTo

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:1424

### `Protected` _clearResults

- _clearResults(): void

- The function `_clearResults` resets the values of several arrays used for tracking visited nodes and their properties.

  #### Returns void

  Inherited from AbstractBinaryTree._clearResults

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:1504

### `Protected` _getResultByPropertyName

- _getResultByPropertyName(nodeOrPropertyName?): AbstractBinaryTreeNodeProperties<N>

- The function `_getResultByPropertyName` returns the corresponding property value based on the given node or property name.

  #### Parameters

  - ##### `Optional` nodeOrPropertyName: NodeOrPropertyName

    The parameter `nodeOrPropertyName` is an optional parameter that can accept either a `NodeOrPropertyName` type or be undefined.

  #### Returns AbstractBinaryTreeNodeProperties<N>

  The method `_getResultByPropertyName` returns an instance of `AbstractBinaryTreeNodeProperties<N>`.

  Inherited from AbstractBinaryTree._getResultByPropertyName

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:1592

### `Protected` _pushByPropertyNameStopOrNot

- _pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName?, onlyOne?): undefined | boolean

- 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.

  Inherited from AbstractBinaryTree._pushByPropertyNameStopOrNot

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:1525

### `Protected` _setLoopType

- _setLoopType(value): void

- The function sets the loop type for a protected variable.

  #### Parameters

  - ##### value: LoopType

    The value parameter is of type LoopType.

  #### Returns void

  Inherited from AbstractBinaryTree._setLoopType

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:1452

### `Protected` _setRoot

- _setRoot(v): void

- 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

  Inherited from AbstractBinaryTree._setRoot

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:1485

### `Protected` _setSize

- _setSize(v): void

- The function sets the size of a protected variable.

  #### Parameters

  - ##### v: number

    number

  #### Returns void

  Inherited from AbstractBinaryTree._setSize

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:1496

### `Protected` _setVisitedId

- _setVisitedId(value): void

- The function sets the value of the `_visitedId` property in a protected manner.

  #### Parameters

  - ##### value: number[]

    value is an array of BinaryTreeNodeId values.

  #### Returns void

  Inherited from AbstractBinaryTree._setVisitedId

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:1460

### `Protected` _setVisitedNode

- _setVisitedNode(value): void

- The function sets the value of the _visitedNode property.

  #### Parameters

  - ##### value: N[]

    N[] is an array of elements of type N.

  #### Returns void

  Inherited from AbstractBinaryTree._setVisitedNode

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:1476

### `Protected` _setVisitedVal

- _setVisitedVal(value): void

- The function sets the value of the "_visitedVal" property to the given array.

  #### Parameters

  - ##### value: N[]

    An array of type N.

  #### Returns void

  Inherited from AbstractBinaryTree._setVisitedVal

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:1468

### add

- add(idOrNode, val?): undefined | null | N

- The `add` function adds a new node to a binary tree, either by ID or by creating a new node with a given value.

  #### Parameters

  - ##### idOrNode: null | number | N

    The `idOrNode` parameter can be either a `BinaryTreeNodeId`, which is a number representing the ID of a binary tree node, or it can be a `N` object, which represents a binary tree node itself. It can also be `null` if no node is specified.

  - ##### `Optional` val: N["val"]

    The `val` parameter is an optional value that can be assigned to the `val` property of the new node being added to the binary tree.

  #### Returns undefined | null | N

  The function `add` returns either the inserted node (`N`), `null`, or `undefined`.

  Implementation of IBinaryTree.add

  Inherited from AbstractBinaryTree.add

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:249

### addMany

- addMany(idsOrNodes, data?): (undefined | null | N)[]

- The `addMany` function takes an array of binary tree node IDs or nodes, and optionally an array of corresponding data values, and adds them to the binary tree.

  #### Parameters

  - ##### idsOrNodes: (null | number)[] | (null | N)[]

    An array of BinaryTreeNodeId or BinaryTreeNode objects, or null values.

  - ##### `Optional` data: N["val"][]

    The `data` parameter is an optional array of values (`N['val'][]`) that corresponds to the nodes or node IDs being added. It is used to set the value of each node being added. If `data` is not provided, the value of the nodes will be `undefined`.

  #### Returns (undefined | null | N)[]

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

  Implementation of IBinaryTree.addMany

  Inherited from AbstractBinaryTree.addMany

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:308

### clear

- clear(): void

- The clear() function resets the root, size, and maxId properties to their initial values.

  #### Returns void

  Implementation of IBinaryTree.clear

  Inherited from AbstractBinaryTree.clear

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:221

### createNode

- createNode(id, val?): N

- The function creates a new binary tree node with an optional value.

  #### Parameters

  - ##### id: number

    The `id` parameter is the identifier for the binary tree node. It is of type `BinaryTreeNodeId`, which represents the unique identifier for each node in the binary tree.

  - ##### `Optional` val: N["val"]

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

  #### Returns N

  a new instance of a BinaryTreeNode with the specified id and value.

  Implementation of IBinaryTree.createNode

  Overrides AbstractBinaryTree.createNode

  - Defined in src/data-structures/binary-tree/binary-tree.ts:44

### fill

- fill(idsOrNodes, data?): boolean

- 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["val"][] | N[]

    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.

  Implementation of IBinaryTree.fill

  Inherited from AbstractBinaryTree.fill

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:339

### get

- get(nodeProperty, propertyName?): null | N

- The function returns the first node that matches the given property name and value, or null if no matching node is found.

  #### 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 search for.

  - ##### `Optional` propertyName: BinaryTreeNodePropertyName

    The `propertyName` parameter is an optional parameter that specifies the property name to be used for searching the binary tree nodes. If this parameter is not provided, the default value is set to `'id'`.

  #### Returns null | N

  either the value of the specified property of the node, or the node itself if no property name is provided. If no matching node is found, it returns null.

  Implementation of IBinaryTree.get

  Inherited from AbstractBinaryTree.get

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:585

### getDepth

- getDepth(beginRoot): number

- The function calculates the depth of a node in a binary tree.

  #### Parameters

  - ##### beginRoot: null | number | N

    The `beginRoot` parameter can be one of the following:

  #### Returns number

  the depth of the given node or binary tree.

  Implementation of IBinaryTree.getDepth

  Inherited from AbstractBinaryTree.getDepth

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:398

### getHeight

- getHeight(beginRoot?): number

- 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.

  Implementation of IBinaryTree.getHeight

  Inherited from AbstractBinaryTree.getHeight

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:416

### getLeftMost

- getLeftMost(): null | N

- The function `getLeftMost` returns the leftmost node in a binary tree, starting from a specified node or the root if no node is specified. generic type representing a node in a binary tree), `BinaryTreeNodeId` (a type representing the ID of a binary tree node), or `null`.

  #### 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. The function returns the leftmost node found during the traversal. If no leftmost node is found (

  Implementation of IBinaryTree.getLeftMost

  Inherited from AbstractBinaryTree.getLeftMost

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:624
- getLeftMost(node?): N

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

  #### Parameters

  - ##### `Optional` node: 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).

  #### 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. The function returns the leftmost node found during the traversal. If no leftmost node is found (

  Implementation of IBinaryTree.getLeftMost

  Inherited from AbstractBinaryTree.getLeftMost

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:637

### getMinHeight

- getMinHeight(beginRoot?): number

- 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.

  Implementation of IBinaryTree.getMinHeight

  Inherited from AbstractBinaryTree.getMinHeight

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:465

### getNodes

- getNodes(nodeProperty, propertyName?, onlyOne?): N[]

- The function `getNodes` returns an array of nodes that match a given property name and value in a binary tree.

  #### 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 when searching for nodes. 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 `propertyName`. If `onlyOne` is set to `true`, the function will stop traversing the tree and return the first matching node. If `only

  #### Returns N[]

  an array of nodes (type N).

  Implementation of IBinaryTree.getNodes

  Inherited from AbstractBinaryTree.getNodes

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:530

### getPathToRoot

- getPathToRoot(node, isReverse?): 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[]`).

  Implementation of IBinaryTree.getPathToRoot

  Inherited from AbstractBinaryTree.getPathToRoot

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:601

### getPredecessor

- getPredecessor(node): N

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

  #### Parameters

  - ##### node: N

    The parameter `node` is a BinaryTreeNode object, representing a node in a binary tree.

  #### Returns N

  the predecessor of the given node in a binary tree.

  Implementation of IBinaryTree.getPredecessor

  Inherited from AbstractBinaryTree.getPredecessor

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:1270

### getRightMost

- getRightMost(): null | N

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

  #### Returns null | N

  The `getRightMost` function returns the rightmost node in a binary tree. It returns the rightmost node starting from the root of the binary tree.

  Implementation of IBinaryTree.getRightMost

  Inherited from AbstractBinaryTree.getRightMost

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:680
- getRightMost(node?): N

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

  #### Parameters

  - ##### `Optional` 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 function will default to using the root node of the data structure.

  #### Returns N

  The `getRightMost` function returns the rightmost node in a binary tree. It returns the rightmost node starting from that node.

  Implementation of IBinaryTree.getRightMost

  Inherited from AbstractBinaryTree.getRightMost

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:691

### getSubTreeSize

- getSubTreeSize(subTreeRoot): number

- The function calculates the size of a subtree by traversing it either recursively or iteratively.

  #### Parameters

  - ##### subTreeRoot: undefined | null | N

    The `subTreeRoot` parameter represents the root node of a subtree in a binary tree.

  #### Returns number

  the size of the subtree rooted at `subTreeRoot`.

  Implementation of IBinaryTree.getSubTreeSize

  Inherited from AbstractBinaryTree.getSubTreeSize

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:775

### has

- has(nodeProperty, propertyName?): boolean

- 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.

  Implementation of IBinaryTree.has

  Inherited from AbstractBinaryTree.has

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:568

### isBST

- isBST(): boolean

- The function isBST checks if the binary tree is valid binary search tree.

  #### Returns boolean

  The `isBST()` function is returning a boolean value.

  Implementation of IBinaryTree.isBST

  Inherited from AbstractBinaryTree.isBST

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:765

### isEmpty

- isEmpty(): boolean

- The function checks if the size of an object is equal to zero and returns a boolean value.

  #### Returns boolean

  A boolean value indicating whether the size of the object is 0 or not.

  Implementation of IBinaryTree.isEmpty

  Inherited from AbstractBinaryTree.isEmpty

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:231

### isPerfectlyBalanced

- isPerfectlyBalanced(beginRoot?): boolean

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

  #### Parameters

  - ##### `Optional` beginRoot: null | N

    The parameter `beginRoot` is of type `N` or `null`. It represents the root node of a tree or null if the tree is empty.

  #### Returns boolean

  The method is returning a boolean value.

  Implementation of IBinaryTree.isPerfectlyBalanced

  Inherited from AbstractBinaryTree.isPerfectlyBalanced

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:515

### isSubtreeBST

- isSubtreeBST(node): boolean

- The function checks if a binary search tree is valid by traversing it either recursively or iteratively.

  #### Parameters

  - ##### node: null | N

    The `node` parameter represents the root node of a binary search tree (BST).

  #### Returns boolean

  a boolean value.

  Implementation of IBinaryTree.isSubtreeBST

  Inherited from AbstractBinaryTree.isSubtreeBST

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:731

### levelIterative

- levelIterative(node): number[]

- Performs a level-order traversal on a binary tree starting from the specified node and accumulates properties of each node based on their 'id' property.

  #### Parameters

  - ##### node: null | N

    The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.

  #### Returns number[]

  An array of binary tree node IDs.

  Implementation of IBinaryTree.levelIterative

  Inherited from AbstractBinaryTree.levelIterative

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:1116
- levelIterative(node, nodeOrPropertyName?): number[]

- Performs a level-order traversal on a binary tree starting from the specified node and accumulates properties of each node based on the specified property name.

  #### Parameters

  - ##### node: null | N

    The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.

  - ##### `Optional` nodeOrPropertyName: "id"

    The name of the property to accumulate.

  #### Returns number[]

  An array of values corresponding to the specified property.

  Implementation of IBinaryTree.levelIterative

  Inherited from AbstractBinaryTree.levelIterative

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:1124
- levelIterative(node, nodeOrPropertyName?): N["val"][]

- Performs a level-order traversal on a binary tree starting from the specified node and accumulates the 'val' property of each node.

  #### Parameters

  - ##### node: null | N

    The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.

  - ##### `Optional` nodeOrPropertyName: "val"

    The name of the property to accumulate.

  #### Returns N["val"][]

  An array of 'val' properties from each node.

  Implementation of IBinaryTree.levelIterative

  Inherited from AbstractBinaryTree.levelIterative

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:1132
- levelIterative(node, nodeOrPropertyName?): N[]

- Performs a level-order traversal on a binary tree starting from the specified node and accumulates nodes themselves.

  #### Parameters

  - ##### node: null | N

    The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.

  - ##### `Optional` nodeOrPropertyName: "node"

    The name of the property to accumulate.

  #### Returns N[]

  An array of binary tree nodes.

  Implementation of IBinaryTree.levelIterative

  Inherited from AbstractBinaryTree.levelIterative

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:1140

### listLevels

- listLevels(node): number[][]

- Collects nodes from a binary tree by a specified property and organizes them into levels.

  #### Parameters

  - ##### node: null | N

    The root node of the binary tree or null. If null, the function will use the root node of the current binary tree instance.

  #### Returns number[][]

  A 2D array of AbstractBinaryTreeNodeProperty objects.

  Implementation of IBinaryTree.listLevels

  Inherited from AbstractBinaryTree.listLevels

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:1183
- listLevels(node, nodeOrPropertyName?): number[][]

- Collects nodes from a binary tree by a specified property and organizes them into levels.

  #### Parameters

  - ##### node: null | N

    The root node of the binary tree or null. If null, the function will use the root node of the current binary tree instance.

  - ##### `Optional` nodeOrPropertyName: "id"

  #### Returns number[][]

  Implementation of IBinaryTree.listLevels

  Inherited from AbstractBinaryTree.listLevels

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:1191
- listLevels(node, nodeOrPropertyName?): N["val"][][]

- Collects nodes from a binary tree by a specified property and organizes them into levels.

  #### Parameters

  - ##### node: null | N

    The root node of the binary tree or null. If null, the function will use the root node of the current binary tree instance.

  - ##### `Optional` nodeOrPropertyName: "val"

    The property of the BinaryTreeNode object to collect at each level.

  #### Returns N["val"][][]

  A 2D array of 'val' properties from each node.

  Implementation of IBinaryTree.listLevels

  Inherited from AbstractBinaryTree.listLevels

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:1199
- listLevels(node, nodeOrPropertyName?): N[][]

- Collects nodes from a binary tree by a specified property and organizes them into levels.

  #### Parameters

  - ##### node: null | N

    The root node of the binary tree or null. If null, the function will use the root node of the current binary tree instance.

  - ##### `Optional` nodeOrPropertyName: "node"

    The property of the BinaryTreeNode object to collect at each level.

  #### Returns N[][]

  A 2D array of binary tree nodes.

  Implementation of IBinaryTree.listLevels

  Inherited from AbstractBinaryTree.listLevels

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:1207

### morris

- morris(): number[]

- Performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm.

  #### Returns number[]

  An array of binary tree node IDs.

  Implementation of IBinaryTree.morris

  Inherited from AbstractBinaryTree.morris

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:1293
- morris(pattern?, nodeOrPropertyName?): number[]

- Performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm and accumulates properties of each node based on the specified property name.

  #### Parameters

  - ##### `Optional` pattern: DFSOrderPattern

    The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).

  - ##### `Optional` nodeOrPropertyName: "id"

    The name of the property to accumulate.

  #### Returns number[]

  An array of values corresponding to the specified property.

  Implementation of IBinaryTree.morris

  Inherited from AbstractBinaryTree.morris

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:1301
- morris(pattern?, nodeOrPropertyName?): N[]

- Performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm and accumulates the 'val' property of each node.

  #### Parameters

  - ##### `Optional` pattern: DFSOrderPattern

    The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).

  - ##### `Optional` nodeOrPropertyName: "val"

    The property of the BinaryTreeNode object to collect at each level.

  #### Returns N[]

  An array of 'val' properties from each node.

  Implementation of IBinaryTree.morris

  Inherited from AbstractBinaryTree.morris

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:1309
- morris(pattern?, nodeOrPropertyName?): N[]

- Performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm and accumulates nodes themselves.

  #### Parameters

  - ##### `Optional` pattern: DFSOrderPattern

    The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).

  - ##### `Optional` nodeOrPropertyName: "node"

    The property of the BinaryTreeNode object to collect at each level.

  #### Returns N[]

  An array of binary tree nodes.

  Implementation of IBinaryTree.morris

  Inherited from AbstractBinaryTree.morris

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:1317

### remove

- remove(nodeOrId): BinaryTreeDeletedResult<N>[]

- The `remove` function in TypeScript is used to delete a node from a binary search tree and returns an array of objects containing the deleted node and the node that needs to be balanced.

  #### Parameters

  - ##### nodeOrId: number | N

    The `nodeOrId` parameter can be either a node object (`N`) or a binary tree node ID (`BinaryTreeNodeId`).

  #### Returns BinaryTreeDeletedResult<N>[]

  The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.

  Implementation of IBinaryTree.remove

  Inherited from AbstractBinaryTree.remove

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:351

### subTreeAdd

- subTreeAdd(subTreeRoot, delta, propertyName?): boolean

- 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.

  Implementation of IBinaryTree.subTreeAdd

  Inherited from AbstractBinaryTree.subTreeAdd

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:868

### subTreeSum

- subTreeSum(subTreeRoot, propertyName?): number

- 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`.

  Implementation of IBinaryTree.subTreeSum

  Inherited from AbstractBinaryTree.subTreeSum

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:812

### swapLocation

- swapLocation(srcNode, destNode): N

- 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.

  Implementation of IBinaryTree.swapLocation

  Inherited from AbstractBinaryTree.swapLocation

  - Defined in src/data-structures/binary-tree/abstract-binary-tree.ts:199

Generated using TypeDoc