undirected-graph-typed 1.47.6 → 1.47.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/dist/data-structures/binary-tree/avl-tree.d.ts +40 -22
  2. package/dist/data-structures/binary-tree/avl-tree.js +45 -36
  3. package/dist/data-structures/binary-tree/binary-tree.d.ts +105 -113
  4. package/dist/data-structures/binary-tree/binary-tree.js +133 -119
  5. package/dist/data-structures/binary-tree/bst.d.ts +53 -44
  6. package/dist/data-structures/binary-tree/bst.js +137 -154
  7. package/dist/data-structures/binary-tree/rb-tree.d.ts +48 -15
  8. package/dist/data-structures/binary-tree/rb-tree.js +70 -33
  9. package/dist/data-structures/binary-tree/tree-multimap.d.ts +26 -37
  10. package/dist/data-structures/binary-tree/tree-multimap.js +58 -137
  11. package/dist/data-structures/hash/hash-map.d.ts +2 -6
  12. package/dist/data-structures/hash/hash-map.js +5 -8
  13. package/dist/data-structures/trie/trie.d.ts +3 -0
  14. package/dist/data-structures/trie/trie.js +19 -4
  15. package/dist/interfaces/binary-tree.d.ts +3 -3
  16. package/dist/types/common.d.ts +6 -1
  17. package/dist/types/data-structures/hash/hash-map.d.ts +1 -2
  18. package/package.json +2 -2
  19. package/src/data-structures/binary-tree/avl-tree.ts +59 -39
  20. package/src/data-structures/binary-tree/binary-tree.ts +192 -180
  21. package/src/data-structures/binary-tree/bst.ts +157 -154
  22. package/src/data-structures/binary-tree/rb-tree.ts +78 -37
  23. package/src/data-structures/binary-tree/tree-multimap.ts +67 -145
  24. package/src/data-structures/hash/hash-map.ts +8 -8
  25. package/src/data-structures/trie/trie.ts +23 -4
  26. package/src/interfaces/binary-tree.ts +3 -3
  27. package/src/types/common.ts +11 -1
  28. package/src/types/data-structures/hash/hash-map.ts +1 -2
@@ -5,8 +5,8 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback, BTNKey } from '../../types';
9
- import { BinaryTreeNested, BinaryTreePrintOptions, BiTreeDeleteResult, DFSOrderPattern, FamilyPosition, IterableEntriesOrKeys, IterationType, NodeDisplayLayout } from '../../types';
8
+ import type { BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback, BTNKey, BTNodeEntry, BTNodeExemplar, BTNodeKeyOrNode } from '../../types';
9
+ import { BinaryTreeNested, BinaryTreePrintOptions, BiTreeDeleteResult, DFSOrderPattern, FamilyPosition, IterationType, NodeDisplayLayout } from '../../types';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  /**
12
12
  * Represents a node in a binary tree.
@@ -14,43 +14,15 @@ import { IBinaryTree } from '../../interfaces';
14
14
  * @template N - The type of the family relationship in the binary tree.
15
15
  */
16
16
  export declare class BinaryTreeNode<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode<V, BinaryTreeNodeNested<V>>> {
17
- /**
18
- * The key associated with the node.
19
- */
20
17
  key: BTNKey;
21
- /**
22
- * The value stored in the node.
23
- */
24
18
  value?: V;
25
- /**
26
- * The parent node of the current node.
27
- */
28
- parent?: N | null;
29
- /**
30
- * Creates a new instance of BinaryTreeNode.
31
- * @param {BTNKey} key - The key associated with the node.
32
- * @param {V} value - The value stored in the node.
33
- */
19
+ parent?: N;
34
20
  constructor(key: BTNKey, value?: V);
35
21
  protected _left?: N | null;
36
- /**
37
- * Get the left child node.
38
- */
39
22
  get left(): N | null | undefined;
40
- /**
41
- * Set the left child node.
42
- * @param {N | null | undefined} v - The left child node.
43
- */
44
23
  set left(v: N | null | undefined);
45
24
  protected _right?: N | null;
46
- /**
47
- * Get the right child node.
48
- */
49
25
  get right(): N | null | undefined;
50
- /**
51
- * Set the right child node.
52
- * @param {N | null | undefined} v - The right child node.
53
- */
54
26
  set right(v: N | null | undefined);
55
27
  /**
56
28
  * Get the position of the node within its family.
@@ -59,25 +31,31 @@ export declare class BinaryTreeNode<V = any, N extends BinaryTreeNode<V, N> = Bi
59
31
  get familyPosition(): FamilyPosition;
60
32
  }
61
33
  /**
62
- * Represents a binary tree data structure.
63
- * @template N - The type of the binary tree's nodes.
34
+ * 1. Two Children Maximum: Each node has at most two children.
35
+ * 2. Left and Right Children: Nodes have distinct left and right children.
36
+ * 3. Depth and Height: Depth is the number of edges from the root to a node; height is the maximum depth in the tree.
37
+ * 4. Subtrees: Each child of a node forms the root of a subtree.
38
+ * 5. Leaf Nodes: Nodes without children are leaves.
39
+ * 6. Internal Nodes: Nodes with at least one child are internal.
40
+ * 7. Balanced Trees: The heights of the left and right subtrees of any node differ by no more than one.
41
+ * 8. Full Trees: Every node has either 0 or 2 children.
42
+ * 9. Complete Trees: All levels are fully filled except possibly the last, filled from left to right.
64
43
  */
65
44
  export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode<V, BinaryTreeNodeNested<V>>, TREE extends BinaryTree<V, N, TREE> = BinaryTree<V, N, BinaryTreeNested<V, N>>> implements IBinaryTree<V, N, TREE> {
66
45
  iterationType: IterationType;
67
46
  /**
68
- * Creates a new instance of BinaryTree.
69
- * @param {BinaryTreeOptions} [options] - The options for the binary tree.
47
+ * The constructor function initializes a binary tree object with optional elements and options.
48
+ * @param [elements] - An optional iterable of BTNodeExemplar objects. These objects represent the
49
+ * elements to be added to the binary tree.
50
+ * @param [options] - The `options` parameter is an optional object that can contain additional
51
+ * configuration options for the binary tree. In this case, it is of type
52
+ * `Partial<BinaryTreeOptions>`, which means that not all properties of `BinaryTreeOptions` are
53
+ * required.
70
54
  */
71
- constructor(elements?: IterableEntriesOrKeys<V>, options?: Partial<BinaryTreeOptions>);
55
+ constructor(elements?: Iterable<BTNodeExemplar<V, N>>, options?: Partial<BinaryTreeOptions>);
72
56
  protected _root?: N | null;
73
- /**
74
- * Get the root node of the binary tree.
75
- */
76
57
  get root(): N | null | undefined;
77
58
  protected _size: number;
78
- /**
79
- * Get the number of nodes in the binary tree.
80
- */
81
59
  get size(): number;
82
60
  /**
83
61
  * Creates a new instance of BinaryTreeNode with the given key and value.
@@ -86,41 +64,51 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
86
64
  * @returns {N} - The newly created BinaryTreeNode.
87
65
  */
88
66
  createNode(key: BTNKey, value?: V): N;
67
+ /**
68
+ * The function creates a binary tree with the given options.
69
+ * @param [options] - The `options` parameter is an optional object that allows you to customize the
70
+ * behavior of the `BinaryTree` class. It is of type `Partial<BinaryTreeOptions>`, which means that
71
+ * you can provide only a subset of the properties defined in the `BinaryTreeOptions` interface.
72
+ * @returns a new instance of a binary tree.
73
+ */
89
74
  createTree(options?: Partial<BinaryTreeOptions>): TREE;
90
75
  /**
91
- * Time Complexity: O(n)
92
- * Space Complexity: O(1)
76
+ * The function checks if a given value is an entry in a binary tree node.
77
+ * @param kne - BTNodeExemplar<V, N> - A generic type representing a node in a binary tree. It has
78
+ * two type parameters V and N, representing the value and node type respectively.
79
+ * @returns a boolean value.
80
+ */
81
+ isEntry(kne: BTNodeExemplar<V, N>): kne is BTNodeEntry<V>;
82
+ /**
83
+ * Time Complexity O(log n) - O(n)
84
+ * Space Complexity O(1)
85
+ */
86
+ /**
87
+ * Time Complexity O(log n) - O(n)
88
+ * Space Complexity O(1)
93
89
  *
94
- * The `add` function adds a new node with a key and value to a binary tree, or updates the value of
95
- * an existing node with the same key.
96
- * @param {BTNKey | N | null | undefined} keyOrNode - The `keyOrNode` parameter can be one of the
97
- * following types:
98
- * @param {V} [value] - The value to be associated with the key or node being added to the binary
99
- * tree.
100
- * @returns The function `add` returns a node (`N`) if it was successfully inserted into the binary
101
- * tree, or `null` or `undefined` if the insertion was not successful.
90
+ * The `add` function adds a new node to a binary tree, either by key or by providing a node object.
91
+ * @param keyOrNodeOrEntry - The parameter `keyOrNodeOrEntry` can be one of the following:
92
+ * @returns The function `add` returns the inserted node (`N`), `null`, or `undefined`.
102
93
  */
103
- add(keyOrNode: BTNKey | N | null | undefined, value?: V): N | null | undefined;
94
+ add(keyOrNodeOrEntry: BTNodeExemplar<V, N>): N | null | undefined;
104
95
  /**
105
- * Time Complexity: O(n)
96
+ * Time Complexity: O(k log n) - O(k * n)
106
97
  * Space Complexity: O(1)
107
98
  * Comments: The time complexity for adding a node depends on the depth of the tree. In the best case (when the tree is empty), it's O(1). In the worst case (when the tree is a degenerate tree), it's O(n). The space complexity is constant.
108
99
  */
109
100
  /**
110
- * Time Complexity: O(k * n) "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted.
101
+ * Time Complexity: O(k log n) - O(k * n)
111
102
  * Space Complexity: O(1)
112
103
  *
113
- * The `addMany` function takes an array of keys or nodes and an optional array of values, and adds
114
- * each key-value pair to a data structure.
115
- * @param {(BTNKey | N |null | undefined)[]} keysOrNodes - An array of keys or nodes to be added to
116
- * the binary search tree. Each element can be of type `BTNKey` (a key value), `N` (a node), `null`,
117
- * or `undefined`.
118
- * @param {(V | undefined)[]} [values] - The `values` parameter is an optional array of values that
119
- * correspond to the keys or nodes being added. If provided, the values will be associated with the
120
- * keys or nodes during the add operation.
121
- * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
122
- */
123
- addMany(keysOrNodes: (BTNKey | N | null | undefined)[], values?: (V | undefined)[]): (N | null | undefined)[];
104
+ * The function `addMany` takes in an iterable of `BTNodeExemplar` objects, adds each object to the
105
+ * current instance, and returns an array of the inserted nodes.
106
+ * @param nodes - The `nodes` parameter is an iterable (such as an array or a set) of
107
+ * `BTNodeExemplar<V, N>` objects.
108
+ * @returns The function `addMany` returns an array of values, where each value is either of type
109
+ * `N`, `null`, or `undefined`.
110
+ */
111
+ addMany(nodes: Iterable<BTNodeExemplar<V, N>>): (N | null | undefined)[];
124
112
  /**
125
113
  * Time Complexity: O(k * n) "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted.
126
114
  * Space Complexity: O(1)
@@ -129,15 +117,11 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
129
117
  * Time Complexity: O(k * n) "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted.
130
118
  * Space Complexity: O(1)
131
119
  *
132
- * The `refill` function clears the binary tree and adds multiple nodes with the given IDs or nodes and optional data.
133
- * @param {(BTNKey | N)[]} keysOrNodes - The `keysOrNodes` parameter is an array that can contain either
134
- * `BTNKey` or `N` values.
135
- * @param {N[] | Array<V>} [values] - The `data` parameter is an optional array of values that will be assigned to
136
- * the nodes being added. If provided, the length of the `data` array should be equal to the length of the `keysOrNodes`
137
- * array. Each value in the `data` array will be assigned to the
138
- * @returns The method is returning a boolean value.
120
+ * The `refill` function clears the current collection and adds new nodes, keys, or entries to it.
121
+ * @param nodesOrKeysOrEntries - The parameter `nodesOrKeysOrEntries` is an iterable object that can
122
+ * contain either `BTNodeExemplar` objects, keys, or entries.
139
123
  */
140
- refill(keysOrNodes: (BTNKey | N | null | undefined)[], values?: (V | undefined)[]): boolean;
124
+ refill(nodesOrKeysOrEntries: Iterable<BTNodeExemplar<V, N>>): void;
141
125
  /**
142
126
  * Time Complexity: O(k * n) "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted.
143
127
  * Space Complexity: O(1)
@@ -162,7 +146,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
162
146
  * `N` (binary tree node) or `null` or `undefined`. If no value is provided for `beginRoot
163
147
  * @returns the depth of the `distNode` relative to the `beginRoot`.
164
148
  */
165
- getDepth(distNode: BTNKey | N | null | undefined, beginRoot?: BTNKey | N | null | undefined): number;
149
+ getDepth(distNode: BTNodeKeyOrNode<N>, beginRoot?: BTNodeKeyOrNode<N>): number;
166
150
  /**
167
151
  * Time Complexity: O(n)
168
152
  * Space Complexity: O(1)
@@ -181,7 +165,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
181
165
  * values:
182
166
  * @returns the height of the binary tree.
183
167
  */
184
- getHeight(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): number;
168
+ getHeight(beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): number;
185
169
  /**
186
170
  * Time Complexity: O(n)
187
171
  * Space Complexity: O(log n)
@@ -200,7 +184,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
200
184
  * to calculate the minimum height of a binary tree. It can have two possible values:
201
185
  * @returns The function `getMinHeight` returns the minimum height of a binary tree.
202
186
  */
203
- getMinHeight(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): number;
187
+ getMinHeight(beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): number;
204
188
  /**
205
189
  * Time Complexity: O(n)
206
190
  * Space Complexity: O(log n)
@@ -217,28 +201,28 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
217
201
  * value of a binary tree node), `N` (a node of a binary tree), `null`, or `undefined`. If
218
202
  * @returns a boolean value.
219
203
  */
220
- isPerfectlyBalanced(beginRoot?: BTNKey | N | null | undefined): boolean;
204
+ isPerfectlyBalanced(beginRoot?: BTNodeKeyOrNode<N>): boolean;
221
205
  /**
222
206
  * Time Complexity: O(n)
223
207
  * Space Complexity: O(log n)
224
208
  */
225
- getNodes<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, onlyOne?: boolean, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N[];
226
- getNodes<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, onlyOne?: boolean, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N[];
227
- getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N[];
209
+ getNodes<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, onlyOne?: boolean, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): N[];
210
+ getNodes<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, onlyOne?: boolean, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): N[];
211
+ getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): N[];
228
212
  /**
229
213
  * Time Complexity: O(n)
230
214
  * Space Complexity: O(log n).
231
215
  */
232
- has<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): boolean;
233
- has<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): boolean;
234
- has<C extends BTNCallback<N>>(identifier: ReturnType<C> | null | undefined, callback: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): boolean;
216
+ has<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): boolean;
217
+ has<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): boolean;
218
+ has<C extends BTNCallback<N>>(identifier: ReturnType<C> | null | undefined, callback: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): boolean;
235
219
  /**
236
220
  * Time Complexity: O(n)
237
221
  * Space Complexity: O(log n).
238
222
  */
239
- getNode<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N | null | undefined;
240
- getNode<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N | null | undefined;
241
- getNode<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N | null | undefined;
223
+ getNode<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): N | null | undefined;
224
+ getNode<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): N | null | undefined;
225
+ getNode<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): N | null | undefined;
242
226
  /**
243
227
  * Time Complexity: O(n)
244
228
  * Space Complexity: O(log n)
@@ -263,7 +247,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
263
247
  * Space Complexity: O(log n)
264
248
  */
265
249
  /**
266
- * The function `ensureNotKey` returns the node corresponding to the given key if it is a valid node
250
+ * The function `ensureNode` returns the node corresponding to the given key if it is a valid node
267
251
  * key, otherwise it returns the key itself.
268
252
  * @param {BTNKey | N | null | undefined} key - The `key` parameter can be of type `BTNKey`, `N`,
269
253
  * `null`, or `undefined`. It represents a key used to identify a node in a binary tree.
@@ -273,10 +257,10 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
273
257
  * @returns either the node corresponding to the given key if it is a valid node key, or the key
274
258
  * itself if it is not a valid node key.
275
259
  */
276
- ensureNotKey(key: BTNKey | N | null | undefined, iterationType?: IterationType): N | null | undefined;
277
- get<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): V | undefined;
278
- get<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): V | undefined;
279
- get<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): V | undefined;
260
+ ensureNode(key: BTNodeKeyOrNode<N>, iterationType?: IterationType): N | null | undefined;
261
+ get<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): V | undefined;
262
+ get<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): V | undefined;
263
+ get<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): V | undefined;
280
264
  /**
281
265
  * Time Complexity: O(n)
282
266
  * Space Complexity: O(log n)
@@ -304,7 +288,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
304
288
  * reversed before returning it. If `isReverse` is set to `false`, the path will be returned as is
305
289
  * @returns The function `getPathToRoot` returns an array of nodes (`N[]`).
306
290
  */
307
- getPathToRoot(beginRoot: BTNKey | N | null | undefined, isReverse?: boolean): N[];
291
+ getPathToRoot(beginRoot: BTNodeKeyOrNode<N>, isReverse?: boolean): N[];
308
292
  /**
309
293
  * Time Complexity: O(log n)
310
294
  * Space Complexity: O(log n)
@@ -323,7 +307,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
323
307
  * @returns The function `getLeftMost` returns the leftmost node (`N`) in the binary tree. If there
324
308
  * is no leftmost node, it returns `null` or `undefined` depending on the input.
325
309
  */
326
- getLeftMost(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N | null | undefined;
310
+ getLeftMost(beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): N | null | undefined;
327
311
  /**
328
312
  * Time Complexity: O(log n)
329
313
  * Space Complexity: O(1)
@@ -343,7 +327,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
343
327
  * @returns The function `getRightMost` returns the rightmost node (`N`) in a binary tree. If there
344
328
  * is no rightmost node, it returns `null` or `undefined`, depending on the input.
345
329
  */
346
- getRightMost(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N | null | undefined;
330
+ getRightMost(beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): N | null | undefined;
347
331
  /**
348
332
  * Time Complexity: O(log n)
349
333
  * Space Complexity: O(1)
@@ -360,7 +344,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
360
344
  * possible values:
361
345
  * @returns a boolean value.
362
346
  */
363
- isSubtreeBST(beginRoot: BTNKey | N | null | undefined, iterationType?: IterationType): boolean;
347
+ isSubtreeBST(beginRoot: BTNodeKeyOrNode<N>, iterationType?: IterationType): boolean;
364
348
  /**
365
349
  * Time Complexity: O(n)
366
350
  * Space Complexity: O(1)
@@ -381,9 +365,9 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
381
365
  * Time Complexity: O(n)
382
366
  * Space Complexity: O(1)
383
367
  */
384
- subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
385
- subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
386
- subTreeTraverse<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
368
+ subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
369
+ subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
370
+ subTreeTraverse<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
387
371
  /**
388
372
  * Time complexity: O(n)
389
373
  * Space complexity: O(log n)
@@ -414,23 +398,23 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
414
398
  * @returns a boolean value indicating whether the potentialKey is of type number or not.
415
399
  */
416
400
  isNodeKey(potentialKey: any): potentialKey is number;
417
- dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
418
- dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
419
- dfs<C extends BTNCallback<N | null | undefined>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
401
+ dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
402
+ dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
403
+ dfs<C extends BTNCallback<N | null | undefined>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
420
404
  /**
421
405
  * Time complexity: O(n)
422
406
  * Space complexity: O(n)
423
407
  */
424
- bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
425
- bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
426
- bfs<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
408
+ bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
409
+ bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
410
+ bfs<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
427
411
  /**
428
412
  * Time complexity: O(n)
429
413
  * Space complexity: O(n)
430
414
  */
431
- listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
432
- listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[][];
433
- listLevels<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
415
+ listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
416
+ listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[][];
417
+ listLevels<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
434
418
  /**
435
419
  * Time complexity: O(n)
436
420
  * Space complexity: O(n)
@@ -461,7 +445,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
461
445
  * `callback` function on each node in the binary tree. The type of the array elements is determined
462
446
  * by the return type of the `callback` function.
463
447
  */
464
- morris<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKey | N | null | undefined): ReturnType<C>[];
448
+ morris<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNodeKeyOrNode<N>): ReturnType<C>[];
465
449
  /**
466
450
  * Time complexity: O(n)
467
451
  * Space complexity: O(1)
@@ -519,8 +503,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
519
503
  * following types:
520
504
  * @param {BinaryTreePrintOptions} [options={ isShowUndefined: false, isShowNull: false, isShowRedBlackNIL: false}] - Options object that controls printing behavior. You can specify whether to display undefined, null, or sentinel nodes.
521
505
  */
522
- print(beginRoot?: BTNKey | N | null | undefined, options?: BinaryTreePrintOptions): void;
523
- init(elements: IterableEntriesOrKeys<V>): void;
506
+ print(beginRoot?: BTNodeKeyOrNode<N>, options?: BinaryTreePrintOptions): void;
524
507
  protected _displayAux(node: N | null | undefined, options: BinaryTreePrintOptions): NodeDisplayLayout;
525
508
  protected _defaultOneParamCallback: (node: N) => number;
526
509
  /**
@@ -529,7 +512,16 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
529
512
  * @param {N} destNode - The destination node to swap.
530
513
  * @returns {N} - The destination node after the swap.
531
514
  */
532
- protected _swap(srcNode: BTNKey | N | null | undefined, destNode: BTNKey | N | null | undefined): N | undefined;
515
+ protected _swapProperties(srcNode: BTNodeKeyOrNode<N>, destNode: BTNodeKeyOrNode<N>): N | undefined;
516
+ /**
517
+ * The function replaces an old node with a new node in a binary tree.
518
+ * @param {N} oldNode - The oldNode parameter represents the node that needs to be replaced in the
519
+ * tree.
520
+ * @param {N} newNode - The `newNode` parameter is the node that will replace the `oldNode` in the
521
+ * tree.
522
+ * @returns The method is returning the newNode.
523
+ */
524
+ protected _replaceNode(oldNode: N, newNode: N): N;
533
525
  /**
534
526
  * The function `_addTo` adds a new node to a binary tree if there is an available position.
535
527
  * @param {N | null | undefined} newNode - The `newNode` parameter represents the node that you want to add to
@@ -541,7 +533,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
541
533
  * the binary tree. If neither the left nor right child is available, the function returns undefined.
542
534
  * If the parent node is null, the function also returns undefined.
543
535
  */
544
- protected _addTo(newNode: N | null | undefined, parent: BTNKey | N | null | undefined): N | null | undefined;
536
+ protected _addTo(newNode: N | null | undefined, parent: BTNodeKeyOrNode<N>): N | null | undefined;
545
537
  /**
546
538
  * The function sets the root property of an object to a given value, and if the value is not null,
547
539
  * it also sets the parent property of the value to undefined.