bst-typed 1.47.5 → 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 (71) hide show
  1. package/dist/data-structures/binary-tree/avl-tree.d.ts +36 -18
  2. package/dist/data-structures/binary-tree/avl-tree.js +46 -29
  3. package/dist/data-structures/binary-tree/binary-tree.d.ts +158 -129
  4. package/dist/data-structures/binary-tree/binary-tree.js +182 -184
  5. package/dist/data-structures/binary-tree/bst.d.ts +73 -63
  6. package/dist/data-structures/binary-tree/bst.js +168 -169
  7. package/dist/data-structures/binary-tree/rb-tree.d.ts +54 -17
  8. package/dist/data-structures/binary-tree/rb-tree.js +77 -31
  9. package/dist/data-structures/binary-tree/tree-multimap.d.ts +29 -40
  10. package/dist/data-structures/binary-tree/tree-multimap.js +66 -136
  11. package/dist/data-structures/graph/abstract-graph.js +1 -1
  12. package/dist/data-structures/hash/hash-map.d.ts +2 -6
  13. package/dist/data-structures/hash/hash-map.js +5 -8
  14. package/dist/data-structures/heap/heap.d.ts +19 -21
  15. package/dist/data-structures/heap/heap.js +52 -34
  16. package/dist/data-structures/heap/max-heap.d.ts +2 -5
  17. package/dist/data-structures/heap/max-heap.js +2 -2
  18. package/dist/data-structures/heap/min-heap.d.ts +2 -5
  19. package/dist/data-structures/heap/min-heap.js +2 -2
  20. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
  21. package/dist/data-structures/linked-list/doubly-linked-list.js +9 -1
  22. package/dist/data-structures/linked-list/singly-linked-list.d.ts +2 -1
  23. package/dist/data-structures/linked-list/singly-linked-list.js +8 -1
  24. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +2 -5
  25. package/dist/data-structures/priority-queue/max-priority-queue.js +2 -2
  26. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +2 -5
  27. package/dist/data-structures/priority-queue/min-priority-queue.js +2 -2
  28. package/dist/data-structures/priority-queue/priority-queue.d.ts +2 -5
  29. package/dist/data-structures/priority-queue/priority-queue.js +2 -2
  30. package/dist/data-structures/queue/deque.d.ts +1 -0
  31. package/dist/data-structures/queue/deque.js +3 -0
  32. package/dist/data-structures/queue/queue.d.ts +1 -0
  33. package/dist/data-structures/queue/queue.js +3 -0
  34. package/dist/data-structures/stack/stack.d.ts +2 -1
  35. package/dist/data-structures/stack/stack.js +10 -2
  36. package/dist/data-structures/trie/trie.d.ts +3 -0
  37. package/dist/data-structures/trie/trie.js +19 -4
  38. package/dist/interfaces/binary-tree.d.ts +4 -2
  39. package/dist/types/common.d.ts +7 -0
  40. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  41. package/dist/types/data-structures/binary-tree/bst.d.ts +2 -2
  42. package/dist/types/data-structures/hash/hash-map.d.ts +1 -2
  43. package/dist/types/data-structures/heap/heap.d.ts +4 -1
  44. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +2 -1
  45. package/package.json +2 -2
  46. package/src/data-structures/binary-tree/avl-tree.ts +61 -31
  47. package/src/data-structures/binary-tree/binary-tree.ts +283 -254
  48. package/src/data-structures/binary-tree/bst.ts +193 -170
  49. package/src/data-structures/binary-tree/rb-tree.ts +87 -32
  50. package/src/data-structures/binary-tree/tree-multimap.ts +76 -136
  51. package/src/data-structures/graph/abstract-graph.ts +1 -1
  52. package/src/data-structures/hash/hash-map.ts +8 -8
  53. package/src/data-structures/heap/heap.ts +57 -39
  54. package/src/data-structures/heap/max-heap.ts +5 -5
  55. package/src/data-structures/heap/min-heap.ts +5 -5
  56. package/src/data-structures/linked-list/doubly-linked-list.ts +10 -1
  57. package/src/data-structures/linked-list/singly-linked-list.ts +9 -1
  58. package/src/data-structures/priority-queue/max-priority-queue.ts +4 -3
  59. package/src/data-structures/priority-queue/min-priority-queue.ts +12 -12
  60. package/src/data-structures/priority-queue/priority-queue.ts +3 -3
  61. package/src/data-structures/queue/deque.ts +4 -0
  62. package/src/data-structures/queue/queue.ts +4 -0
  63. package/src/data-structures/stack/stack.ts +12 -3
  64. package/src/data-structures/trie/trie.ts +23 -4
  65. package/src/interfaces/binary-tree.ts +14 -2
  66. package/src/types/common.ts +15 -1
  67. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  68. package/src/types/data-structures/binary-tree/bst.ts +2 -3
  69. package/src/types/data-structures/hash/hash-map.ts +1 -2
  70. package/src/types/data-structures/heap/heap.ts +3 -1
  71. package/src/types/data-structures/priority-queue/priority-queue.ts +3 -1
@@ -5,7 +5,7 @@
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';
8
+ import type { BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback, BTNKey, BTNodeEntry, BTNodeExemplar, BTNodeKeyOrNode } from '../../types';
9
9
  import { BinaryTreeNested, BinaryTreePrintOptions, BiTreeDeleteResult, DFSOrderPattern, FamilyPosition, IterationType, NodeDisplayLayout } from '../../types';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  /**
@@ -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
- options: BinaryTreeOptions;
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(options?: 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,26 +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;
89
- createTree(options?: BinaryTreeOptions): TREE;
90
67
  /**
91
- * Time Complexity: O(n)
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
+ */
74
+ createTree(options?: Partial<BinaryTreeOptions>): TREE;
75
+ /**
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)
89
+ *
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`.
93
+ */
94
+ add(keyOrNodeOrEntry: BTNodeExemplar<V, N>): N | null | undefined;
95
+ /**
96
+ * Time Complexity: O(k log n) - O(k * n)
92
97
  * Space Complexity: O(1)
93
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.
94
99
  */
95
100
  /**
96
- * Time Complexity: O(n)
101
+ * Time Complexity: O(k log n) - O(k * n)
97
102
  * Space Complexity: O(1)
98
103
  *
99
- * The `add` function adds a new node with a key and value to a binary tree, or updates the value of
100
- * an existing node with the same key.
101
- * @param {BTNKey | N | null | undefined} keyOrNode - The `keyOrNode` parameter can be one of the
102
- * following types:
103
- * @param {V} [value] - The value to be associated with the key or node being added to the binary
104
- * tree.
105
- * @returns The function `add` returns a node (`N`) if it was successfully inserted into the binary
106
- * tree, or `null` or `undefined` if the insertion was not successful.
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`.
107
110
  */
108
- add(keyOrNode: BTNKey | N | null | undefined, value?: V): N | null | undefined;
111
+ addMany(nodes: Iterable<BTNodeExemplar<V, N>>): (N | null | undefined)[];
109
112
  /**
110
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.
111
114
  * Space Complexity: O(1)
@@ -114,34 +117,15 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
114
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.
115
118
  * Space Complexity: O(1)
116
119
  *
117
- * The `addMany` function takes an array of keys or nodes and an optional array of values, and adds
118
- * each key-value pair to a data structure.
119
- * @param {(BTNKey | N |null | undefined)[]} keysOrNodes - An array of keys or nodes to be added to
120
- * the binary search tree. Each element can be of type `BTNKey` (a key value), `N` (a node), `null`,
121
- * or `undefined`.
122
- * @param {(V | undefined)[]} [values] - The `values` parameter is an optional array of values that
123
- * correspond to the keys or nodes being added. If provided, the values will be associated with the
124
- * keys or nodes during the add operation.
125
- * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
126
- */
127
- addMany(keysOrNodes: (BTNKey | N | null | undefined)[], values?: (V | undefined)[]): (N | null | undefined)[];
128
- /**
129
- * 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
- * Space Complexity: O(1)
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.
131
123
  */
124
+ refill(nodesOrKeysOrEntries: Iterable<BTNodeExemplar<V, N>>): void;
132
125
  /**
133
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.
134
127
  * Space Complexity: O(1)
135
- *
136
- * The `refill` function clears the binary tree and adds multiple nodes with the given IDs or nodes and optional data.
137
- * @param {(BTNKey | N)[]} keysOrNodes - The `keysOrNodes` parameter is an array that can contain either
138
- * `BTNKey` or `N` values.
139
- * @param {N[] | Array<V>} [values] - The `data` parameter is an optional array of values that will be assigned to
140
- * the nodes being added. If provided, the length of the `data` array should be equal to the length of the `keysOrNodes`
141
- * array. Each value in the `data` array will be assigned to the
142
- * @returns The method is returning a boolean value.
143
- */
144
- refill(keysOrNodes: (BTNKey | N | null | undefined)[], values?: (V | undefined)[]): boolean;
128
+ */
145
129
  delete<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C): BiTreeDeleteResult<N>[];
146
130
  delete<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C): BiTreeDeleteResult<N>[];
147
131
  delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C): BiTreeDeleteResult<N>[];
@@ -162,11 +146,10 @@ 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
- * Space Complexity: O(log n)
169
- * Best Case - O(log n) (when using recursive iterationType), Worst Case - O(n) (when using iterative iterationType)
152
+ * Space Complexity: O(1)
170
153
  */
171
154
  /**
172
155
  * Time Complexity: O(n)
@@ -182,7 +165,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
182
165
  * values:
183
166
  * @returns the height of the binary tree.
184
167
  */
185
- getHeight(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType | undefined): number;
168
+ getHeight(beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): number;
186
169
  /**
187
170
  * Time Complexity: O(n)
188
171
  * Space Complexity: O(log n)
@@ -201,10 +184,11 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
201
184
  * to calculate the minimum height of a binary tree. It can have two possible values:
202
185
  * @returns The function `getMinHeight` returns the minimum height of a binary tree.
203
186
  */
204
- getMinHeight(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType | undefined): number;
187
+ getMinHeight(beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): number;
205
188
  /**
206
189
  * Time Complexity: O(n)
207
190
  * Space Complexity: O(log n)
191
+ * Best Case - O(log n) (when using recursive iterationType), Worst Case - O(n) (when using iterative iterationType)
208
192
  */
209
193
  /**
210
194
  * Time Complexity: O(n)
@@ -217,16 +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;
221
- getNodes<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, onlyOne?: boolean, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N[];
222
- getNodes<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, onlyOne?: boolean, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N[];
223
- getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N[];
224
- has<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): boolean;
225
- has<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): boolean;
226
- has<C extends BTNCallback<N>>(identifier: ReturnType<C> | null | undefined, callback: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): boolean;
227
- getNode<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N | null | undefined;
228
- getNode<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N | null | undefined;
229
- getNode<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N | null | undefined;
204
+ isPerfectlyBalanced(beginRoot?: BTNodeKeyOrNode<N>): boolean;
205
+ /**
206
+ * Time Complexity: O(n)
207
+ * Space Complexity: O(log n)
208
+ */
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[];
212
+ /**
213
+ * Time Complexity: O(n)
214
+ * Space Complexity: O(log n).
215
+ */
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;
219
+ /**
220
+ * Time Complexity: O(n)
221
+ * Space Complexity: O(log n).
222
+ */
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;
230
226
  /**
231
227
  * Time Complexity: O(n)
232
228
  * Space Complexity: O(log n)
@@ -247,7 +243,11 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
247
243
  */
248
244
  getNodeByKey(key: BTNKey, iterationType?: IterationType): N | undefined;
249
245
  /**
250
- * The function `ensureNotKey` returns the node corresponding to the given key if it is a valid node
246
+ * Time Complexity: O(n)
247
+ * Space Complexity: O(log n)
248
+ */
249
+ /**
250
+ * The function `ensureNode` returns the node corresponding to the given key if it is a valid node
251
251
  * key, otherwise it returns the key itself.
252
252
  * @param {BTNKey | N | null | undefined} key - The `key` parameter can be of type `BTNKey`, `N`,
253
253
  * `null`, or `undefined`. It represents a key used to identify a node in a binary tree.
@@ -257,10 +257,14 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
257
257
  * @returns either the node corresponding to the given key if it is a valid node key, or the key
258
258
  * itself if it is not a valid node key.
259
259
  */
260
- ensureNotKey(key: BTNKey | N | null | undefined, iterationType?: IterationType): N | null | undefined;
261
- get<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): V | undefined;
262
- get<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): V | undefined;
263
- 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;
264
+ /**
265
+ * Time Complexity: O(n)
266
+ * Space Complexity: O(log n)
267
+ */
264
268
  /**
265
269
  * Clear the binary tree, removing all nodes.
266
270
  */
@@ -270,10 +274,6 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
270
274
  * @returns {boolean} - True if the binary tree is empty, false otherwise.
271
275
  */
272
276
  isEmpty(): boolean;
273
- /**
274
- * Time Complexity: O(log n)
275
- * Space Complexity: O(log n)
276
- */
277
277
  /**
278
278
  * Time Complexity: O(log n)
279
279
  * Space Complexity: O(log n)
@@ -288,10 +288,10 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
288
288
  * reversed before returning it. If `isReverse` is set to `false`, the path will be returned as is
289
289
  * @returns The function `getPathToRoot` returns an array of nodes (`N[]`).
290
290
  */
291
- getPathToRoot(beginRoot: BTNKey | N | null | undefined, isReverse?: boolean): N[];
291
+ getPathToRoot(beginRoot: BTNodeKeyOrNode<N>, isReverse?: boolean): N[];
292
292
  /**
293
293
  * Time Complexity: O(log n)
294
- * Space Complexity: O(1)
294
+ * Space Complexity: O(log n)
295
295
  */
296
296
  /**
297
297
  * Time Complexity: O(log n)
@@ -307,7 +307,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
307
307
  * @returns The function `getLeftMost` returns the leftmost node (`N`) in the binary tree. If there
308
308
  * is no leftmost node, it returns `null` or `undefined` depending on the input.
309
309
  */
310
- getLeftMost(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType | undefined): N | null | undefined;
310
+ getLeftMost(beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): N | null | undefined;
311
311
  /**
312
312
  * Time Complexity: O(log n)
313
313
  * Space Complexity: O(1)
@@ -327,9 +327,9 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
327
327
  * @returns The function `getRightMost` returns the rightmost node (`N`) in a binary tree. If there
328
328
  * is no rightmost node, it returns `null` or `undefined`, depending on the input.
329
329
  */
330
- getRightMost(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType | undefined): N | null | undefined;
330
+ getRightMost(beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): N | null | undefined;
331
331
  /**
332
- * Time Complexity: O(n)
332
+ * Time Complexity: O(log n)
333
333
  * Space Complexity: O(1)
334
334
  */
335
335
  /**
@@ -344,7 +344,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
344
344
  * possible values:
345
345
  * @returns a boolean value.
346
346
  */
347
- isSubtreeBST(beginRoot: BTNKey | N | null | undefined, iterationType?: IterationType | undefined): boolean;
347
+ isSubtreeBST(beginRoot: BTNodeKeyOrNode<N>, iterationType?: IterationType): boolean;
348
348
  /**
349
349
  * Time Complexity: O(n)
350
350
  * Space Complexity: O(1)
@@ -360,10 +360,18 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
360
360
  * expected to be
361
361
  * @returns a boolean value.
362
362
  */
363
- isBST(iterationType?: IterationType | undefined): boolean;
364
- subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
365
- subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
366
- subTreeTraverse<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
363
+ isBST(iterationType?: IterationType): boolean;
364
+ /**
365
+ * Time Complexity: O(n)
366
+ * Space Complexity: O(1)
367
+ */
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>[];
371
+ /**
372
+ * Time complexity: O(n)
373
+ * Space complexity: O(log n)
374
+ */
367
375
  /**
368
376
  * The function checks if a given node is a real node by verifying if it is an instance of
369
377
  * BinaryTreeNode and its key is not NaN.
@@ -390,15 +398,27 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
390
398
  * @returns a boolean value indicating whether the potentialKey is of type number or not.
391
399
  */
392
400
  isNodeKey(potentialKey: any): potentialKey is number;
393
- dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
394
- dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
395
- dfs<C extends BTNCallback<N | null | undefined>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
396
- bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
397
- bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
398
- bfs<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
399
- listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
400
- listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[][];
401
- listLevels<C extends BTNCallback<N | null | undefined>>(callback?: C, 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>[];
404
+ /**
405
+ * Time complexity: O(n)
406
+ * Space complexity: O(n)
407
+ */
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>[];
411
+ /**
412
+ * Time complexity: O(n)
413
+ * Space complexity: O(n)
414
+ */
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>[][];
418
+ /**
419
+ * Time complexity: O(n)
420
+ * Space complexity: O(n)
421
+ */
402
422
  getPredecessor(node: N): N;
403
423
  /**
404
424
  * The function `getSuccessor` returns the next node in a binary tree given a current node.
@@ -407,10 +427,6 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
407
427
  * after the given node in the inorder traversal of the binary tree.
408
428
  */
409
429
  getSuccessor(x?: BTNKey | N | null): N | null | undefined;
410
- /**
411
- * Time complexity: O(n)
412
- * Space complexity: O(1)
413
- */
414
430
  /**
415
431
  * Time complexity: O(n)
416
432
  * Space complexity: O(1)
@@ -429,7 +445,11 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
429
445
  * `callback` function on each node in the binary tree. The type of the array elements is determined
430
446
  * by the return type of the `callback` function.
431
447
  */
432
- 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>[];
449
+ /**
450
+ * Time complexity: O(n)
451
+ * Space complexity: O(1)
452
+ */
433
453
  /**
434
454
  * The `forEach` function iterates over each entry in a tree and calls a callback function with the
435
455
  * entry and the tree as arguments.
@@ -483,7 +503,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
483
503
  * following types:
484
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.
485
505
  */
486
- print(beginRoot?: BTNKey | N | null | undefined, options?: BinaryTreePrintOptions): void;
506
+ print(beginRoot?: BTNodeKeyOrNode<N>, options?: BinaryTreePrintOptions): void;
487
507
  protected _displayAux(node: N | null | undefined, options: BinaryTreePrintOptions): NodeDisplayLayout;
488
508
  protected _defaultOneParamCallback: (node: N) => number;
489
509
  /**
@@ -492,7 +512,16 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
492
512
  * @param {N} destNode - The destination node to swap.
493
513
  * @returns {N} - The destination node after the swap.
494
514
  */
495
- 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;
496
525
  /**
497
526
  * The function `_addTo` adds a new node to a binary tree if there is an available position.
498
527
  * @param {N | null | undefined} newNode - The `newNode` parameter represents the node that you want to add to
@@ -504,7 +533,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
504
533
  * the binary tree. If neither the left nor right child is available, the function returns undefined.
505
534
  * If the parent node is null, the function also returns undefined.
506
535
  */
507
- 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;
508
537
  /**
509
538
  * The function sets the root property of an object to a given value, and if the value is not null,
510
539
  * it also sets the parent property of the value to undefined.