min-heap-typed 1.50.0 → 1.50.2

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 (67) hide show
  1. package/dist/data-structures/base/iterable-base.d.ts +114 -9
  2. package/dist/data-structures/base/iterable-base.js +143 -7
  3. package/dist/data-structures/binary-tree/avl-tree.d.ts +43 -46
  4. package/dist/data-structures/binary-tree/avl-tree.js +68 -71
  5. package/dist/data-structures/binary-tree/binary-tree.d.ts +244 -199
  6. package/dist/data-structures/binary-tree/binary-tree.js +484 -376
  7. package/dist/data-structures/binary-tree/bst.d.ts +54 -74
  8. package/dist/data-structures/binary-tree/bst.js +30 -71
  9. package/dist/data-structures/binary-tree/rb-tree.d.ts +78 -60
  10. package/dist/data-structures/binary-tree/rb-tree.js +84 -89
  11. package/dist/data-structures/binary-tree/tree-multimap.d.ts +37 -56
  12. package/dist/data-structures/binary-tree/tree-multimap.js +64 -85
  13. package/dist/data-structures/graph/abstract-graph.d.ts +1 -0
  14. package/dist/data-structures/graph/abstract-graph.js +3 -0
  15. package/dist/data-structures/graph/directed-graph.d.ts +14 -0
  16. package/dist/data-structures/graph/directed-graph.js +26 -0
  17. package/dist/data-structures/graph/map-graph.d.ts +8 -0
  18. package/dist/data-structures/graph/map-graph.js +14 -0
  19. package/dist/data-structures/graph/undirected-graph.d.ts +16 -0
  20. package/dist/data-structures/graph/undirected-graph.js +25 -0
  21. package/dist/data-structures/hash/hash-map.d.ts +121 -15
  22. package/dist/data-structures/hash/hash-map.js +160 -25
  23. package/dist/data-structures/heap/heap.d.ts +66 -6
  24. package/dist/data-structures/heap/heap.js +66 -6
  25. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +67 -50
  26. package/dist/data-structures/linked-list/doubly-linked-list.js +70 -64
  27. package/dist/data-structures/linked-list/singly-linked-list.d.ts +128 -103
  28. package/dist/data-structures/linked-list/singly-linked-list.js +130 -112
  29. package/dist/data-structures/linked-list/skip-linked-list.d.ts +63 -36
  30. package/dist/data-structures/linked-list/skip-linked-list.js +63 -36
  31. package/dist/data-structures/matrix/matrix.d.ts +35 -4
  32. package/dist/data-structures/matrix/matrix.js +50 -11
  33. package/dist/data-structures/queue/deque.d.ts +49 -19
  34. package/dist/data-structures/queue/deque.js +101 -47
  35. package/dist/data-structures/queue/queue.d.ts +39 -5
  36. package/dist/data-structures/queue/queue.js +47 -5
  37. package/dist/data-structures/stack/stack.d.ts +16 -0
  38. package/dist/data-structures/stack/stack.js +22 -0
  39. package/dist/data-structures/trie/trie.d.ts +38 -1
  40. package/dist/data-structures/trie/trie.js +41 -0
  41. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  42. package/dist/types/data-structures/hash/hash-map.d.ts +4 -3
  43. package/dist/types/utils/utils.d.ts +1 -0
  44. package/package.json +2 -2
  45. package/src/data-structures/base/iterable-base.ts +172 -19
  46. package/src/data-structures/binary-tree/avl-tree.ts +97 -97
  47. package/src/data-structures/binary-tree/binary-tree.ts +674 -671
  48. package/src/data-structures/binary-tree/bst.ts +89 -131
  49. package/src/data-structures/binary-tree/rb-tree.ts +127 -155
  50. package/src/data-structures/binary-tree/tree-multimap.ts +96 -112
  51. package/src/data-structures/graph/abstract-graph.ts +4 -0
  52. package/src/data-structures/graph/directed-graph.ts +30 -0
  53. package/src/data-structures/graph/map-graph.ts +15 -0
  54. package/src/data-structures/graph/undirected-graph.ts +28 -0
  55. package/src/data-structures/hash/hash-map.ts +175 -34
  56. package/src/data-structures/heap/heap.ts +66 -6
  57. package/src/data-structures/linked-list/doubly-linked-list.ts +72 -66
  58. package/src/data-structures/linked-list/singly-linked-list.ts +132 -114
  59. package/src/data-structures/linked-list/skip-linked-list.ts +63 -37
  60. package/src/data-structures/matrix/matrix.ts +52 -12
  61. package/src/data-structures/queue/deque.ts +108 -49
  62. package/src/data-structures/queue/queue.ts +51 -5
  63. package/src/data-structures/stack/stack.ts +24 -0
  64. package/src/data-structures/trie/trie.ts +45 -1
  65. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  66. package/src/types/data-structures/hash/hash-map.ts +4 -3
  67. package/src/types/utils/utils.ts +2 -0
@@ -9,29 +9,15 @@ import type { BSTNested, BSTNodeNested, BSTOptions, BTNCallback, KeyOrNodeOrEntr
9
9
  import { BSTVariant, CP, DFSOrderPattern, IterationType } from '../../types';
10
10
  import { BinaryTree, BinaryTreeNode } from './binary-tree';
11
11
  import { IBinaryTree } from '../../interfaces';
12
- export declare class BSTNode<K = any, V = any, N extends BSTNode<K, V, N> = BSTNodeNested<K, V>> extends BinaryTreeNode<K, V, N> {
13
- parent?: N;
12
+ export declare class BSTNode<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BSTNodeNested<K, V>> extends BinaryTreeNode<K, V, NODE> {
13
+ parent?: NODE;
14
14
  constructor(key: K, value?: V);
15
- protected _left?: N;
16
- /**
17
- * Get the left child node.
18
- */
19
- get left(): N | undefined;
20
- /**
21
- * Set the left child node.
22
- * @param {N | undefined} v - The left child node.
23
- */
24
- set left(v: N | undefined);
25
- protected _right?: N;
26
- /**
27
- * Get the right child node.
28
- */
29
- get right(): N | undefined;
30
- /**
31
- * Set the right child node.
32
- * @param {N | undefined} v - The right child node.
33
- */
34
- set right(v: N | undefined);
15
+ protected _left?: NODE;
16
+ get left(): NODE | undefined;
17
+ set left(v: NODE | undefined);
18
+ protected _right?: NODE;
19
+ get right(): NODE | undefined;
20
+ set right(v: NODE | undefined);
35
21
  }
36
22
  /**
37
23
  * 1. Node Order: Each node's left child has a lesser value, and the right child has a greater value.
@@ -42,7 +28,7 @@ export declare class BSTNode<K = any, V = any, N extends BSTNode<K, V, N> = BSTN
42
28
  * 6. Balance Variability: Can become unbalanced; special types maintain balance.
43
29
  * 7. No Auto-Balancing: Standard BSTs don't automatically balance themselves.
44
30
  */
45
- export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<K, V, BSTNodeNested<K, V>>, TREE extends BST<K, V, N, TREE> = BST<K, V, N, BSTNested<K, V, N>>> extends BinaryTree<K, V, N, TREE> implements IBinaryTree<K, V, N, TREE> {
31
+ export declare class BST<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BSTNode<K, V, BSTNodeNested<K, V>>, TREE extends BST<K, V, NODE, TREE> = BST<K, V, NODE, BSTNested<K, V, NODE>>> extends BinaryTree<K, V, NODE, TREE> implements IBinaryTree<K, V, NODE, TREE> {
46
32
  /**
47
33
  * This is the constructor function for a binary search tree class in TypeScript, which initializes
48
34
  * the tree with optional keysOrNodesOrEntries and options.
@@ -51,9 +37,9 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
51
37
  * @param [options] - The `options` parameter is an optional object that can contain additional
52
38
  * configuration options for the binary search tree. It can have the following properties:
53
39
  */
54
- constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, N>>, options?: BSTOptions<K>);
55
- protected _root?: N;
56
- get root(): N | undefined;
40
+ constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, options?: BSTOptions<K>);
41
+ protected _root?: NODE;
42
+ get root(): NODE | undefined;
57
43
  protected _variant: BSTVariant;
58
44
  get variant(): BSTVariant;
59
45
  /**
@@ -64,7 +50,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
64
50
  * represents the value associated with the node in a binary search tree.
65
51
  * @returns a new instance of the BSTNode class with the specified key and value.
66
52
  */
67
- createNode(key: K, value?: V): N;
53
+ createNode(key: K, value?: V): NODE;
68
54
  /**
69
55
  * The function creates a new binary search tree with the specified options.
70
56
  * @param [options] - The `options` parameter is an optional object that allows you to customize the
@@ -74,18 +60,17 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
74
60
  */
75
61
  createTree(options?: Partial<BSTOptions<K>>): TREE;
76
62
  /**
77
- * The function `exemplarToNode` takes an keyOrNodeOrEntry and returns a node if the keyOrNodeOrEntry is valid,
63
+ * The function `keyValueOrEntryToNode` takes an keyOrNodeOrEntry and returns a node if the keyOrNodeOrEntry is valid,
78
64
  * otherwise it returns undefined.
79
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`, where:
65
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`, where:
80
66
  * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
81
- * `exemplarToNode` function. It represents the value associated with the keyOrNodeOrEntry node.
82
- * @returns a node of type N or undefined.
67
+ * `keyValueOrEntryToNode` function. It represents the value associated with the keyOrNodeOrEntry node.
68
+ * @returns a node of type NODE or undefined.
83
69
  */
84
- exemplarToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): N | undefined;
70
+ keyValueOrEntryToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | undefined;
85
71
  /**
86
72
  * Time Complexity: O(log n)
87
73
  * Space Complexity: O(log n)
88
- * Average case for a balanced tree. Space for the recursive call stack in the worst case.
89
74
  */
90
75
  /**
91
76
  * Time Complexity: O(log n)
@@ -93,23 +78,22 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
93
78
  *
94
79
  * The function `ensureNode` returns the node corresponding to the given key if it is a node key,
95
80
  * otherwise it returns the key itself.
96
- * @param {K | N | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `N`, or
81
+ * @param {K | NODE | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `NODE`, or
97
82
  * `undefined`.
98
83
  * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
99
84
  * type of iteration to be performed. It has a default value of `IterationType.ITERATIVE`.
100
- * @returns either a node object (N) or undefined.
85
+ * @returns either a node object (NODE) or undefined.
101
86
  */
102
- ensureNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N | undefined;
87
+ ensureNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | undefined;
103
88
  /**
104
89
  * The function checks if an keyOrNodeOrEntry is an instance of BSTNode.
105
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V, N>`.
90
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V, NODE>`.
106
91
  * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the BSTNode class.
107
92
  */
108
- isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>): keyOrNodeOrEntry is N;
93
+ isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE;
109
94
  /**
110
95
  * Time Complexity: O(log n)
111
96
  * Space Complexity: O(1)
112
- * - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
113
97
  */
114
98
  /**
115
99
  * Time Complexity: O(log n)
@@ -123,15 +107,14 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
123
107
  * @returns The method `add` returns either the newly added node (`newNode`) or `undefined` if the
124
108
  * node was not added.
125
109
  */
126
- add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): boolean;
110
+ add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean;
127
111
  /**
128
112
  * Time Complexity: O(k log n)
129
- * Space Complexity: O(k)
130
- * Adding each element individually in a balanced tree. Additional space is required for the sorted array.
113
+ * Space Complexity: O(k + log n)
131
114
  */
132
115
  /**
133
116
  * Time Complexity: O(k log n)
134
- * Space Complexity: O(k)
117
+ * Space Complexity: O(k + log n)
135
118
  *
136
119
  * The `addMany` function in TypeScript adds multiple keys or nodes to a binary tree, optionally
137
120
  * balancing the tree after each addition.
@@ -147,9 +130,9 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
147
130
  * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
148
131
  * type of iteration to use when adding multiple keys or nodes. It has a default value of
149
132
  * `this.iterationType`, which suggests that it is a property of the current object.
150
- * @returns The function `addMany` returns an array of nodes (`N`) or `undefined` values.
133
+ * @returns The function `addMany` returns an array of nodes (`NODE`) or `undefined` values.
151
134
  */
152
- addMany(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, N>>, values?: Iterable<V | undefined>, isBalanceAdd?: boolean, iterationType?: IterationType): boolean[];
135
+ addMany(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>, isBalanceAdd?: boolean, iterationType?: IterationType): boolean[];
153
136
  /**
154
137
  * Time Complexity: O(log n)
155
138
  * Space Complexity: O(1)
@@ -165,40 +148,39 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
165
148
  * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
166
149
  * type of iteration to use when searching for a node in the binary tree. It can have two possible
167
150
  * values:
168
- * @returns The function `getNodeByKey` returns a node (`N`) if a node with the specified key is
151
+ * @returns The function `getNodeByKey` returns a node (`NODE`) if a node with the specified key is
169
152
  * found in the binary tree. If no node is found, it returns `undefined`.
170
153
  */
171
- getNodeByKey(key: K, iterationType?: IterationType): N | undefined;
154
+ getNodeByKey(key: K, iterationType?: IterationType): NODE | undefined;
172
155
  /**
173
156
  * Time Complexity: O(log n)
174
- * Space Complexity: O(log n)
175
- * Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key. Space for the recursive call stack in the worst case.
157
+ * Space Complexity: O(k + log n)
176
158
  * /
177
159
 
178
160
  /**
179
161
  * Time Complexity: O(log n)
180
- * Space Complexity: O(log n)
162
+ * Space Complexity: O(k + log n)
181
163
  *
182
164
  * The function `getNodes` returns an array of nodes that match a given identifier, using either a
183
165
  * recursive or iterative approach.
184
166
  * @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value that you
185
167
  * want to search for in the nodes of the binary tree. It can be of any type that is returned by the
186
168
  * callback function `C`.
187
- * @param {C} callback - The `callback` parameter is a function that takes a node of type `N` as its
169
+ * @param {C} callback - The `callback` parameter is a function that takes a node of type `NODE` as its
188
170
  * argument and returns a value of type `ReturnType<C>`. The `C` type parameter represents a callback
189
- * function type that extends the `BTNCallback<N>` type. The `BTNCallback<N>` type is
171
+ * function type that extends the `BTNCallback<NODE>` type. The `BTNCallback<NODE>` type is
190
172
  * @param [onlyOne=false] - A boolean flag indicating whether to stop searching after finding the
191
173
  * first node that matches the identifier. If set to true, the function will return an array
192
174
  * containing only the first matching node. If set to false (default), the function will continue
193
175
  * searching for all nodes that match the identifier and return an array containing
194
- * @param {K | N | undefined} beginRoot - The `beginRoot` parameter represents the starting node
176
+ * @param {K | NODE | undefined} beginRoot - The `beginRoot` parameter represents the starting node
195
177
  * for the traversal. It can be either a key value or a node object. If it is undefined, the
196
178
  * traversal will start from the root of the tree.
197
179
  * @param iterationType - The `iterationType` parameter determines the type of iteration to be
198
180
  * performed on the binary tree. It can have two possible values:
199
- * @returns The method returns an array of nodes (`N[]`).
181
+ * @returns The method returns an array of nodes (`NODE[]`).
200
182
  */
201
- getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C> | undefined, callback?: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N[];
183
+ getNodes<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | undefined, callback?: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
202
184
  /**
203
185
  * Time complexity: O(n)
204
186
  * Space complexity: O(n)
@@ -222,7 +204,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
222
204
  * following values:
223
205
  * @returns The method is returning an array of the return type of the callback function.
224
206
  */
225
- dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): ReturnType<C>[];
207
+ dfs<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
226
208
  /**
227
209
  * Time complexity: O(n)
228
210
  * Space complexity: O(n)
@@ -244,7 +226,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
244
226
  * nodes are visited.
245
227
  * @returns The method is returning an array of the return type of the callback function.
246
228
  */
247
- bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): ReturnType<C>[];
229
+ bfs<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
248
230
  /**
249
231
  * Time complexity: O(n)
250
232
  * Space complexity: O(n)
@@ -256,7 +238,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
256
238
  * The function overrides the listLevels method and returns an array of arrays containing the return
257
239
  * type of the callback function for each level of the tree.
258
240
  * @param {C} callback - The `callback` parameter is a generic type `C` that extends
259
- * `BTNCallback<N>`. It represents a callback function that will be called for each node in the tree
241
+ * `BTNCallback<NODE>`. It represents a callback function that will be called for each node in the tree
260
242
  * during the level listing process.
261
243
  * @param beginRoot - The `beginRoot` parameter is used to specify the starting point for listing the
262
244
  * levels of a binary tree. It can be either a key, a node, or an entry in the binary tree. If not
@@ -267,30 +249,28 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
267
249
  * @returns The method is returning a two-dimensional array of the return type of the callback
268
250
  * function.
269
251
  */
270
- listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): ReturnType<C>[][];
252
+ listLevels<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[][];
271
253
  /**
272
- * Time Complexity: O(n log n)
273
- * Space Complexity: O(n)
274
- * Adding each element individually in a balanced tree. Additional space is required for the sorted array.
254
+ * Time Complexity: O(log n)
255
+ * Space Complexity: O(1)
275
256
  */
276
257
  /**
277
- * Time Complexity: O(n log n)
278
- * Space Complexity: O(n)
258
+ * Time Complexity: O(log n)
259
+ * Space Complexity: O(1)
279
260
  *
280
261
  * The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
281
262
  * leftmost node if the comparison result is greater than.
282
- * @param {K | N | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
283
- * type `K`, `N`, or `undefined`. It represents the starting point for finding the last key in
263
+ * @param {K | NODE | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
264
+ * type `K`, `NODE`, or `undefined`. It represents the starting point for finding the last key in
284
265
  * the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).
285
266
  * @returns the key of the rightmost node in the binary tree if the comparison result is less than,
286
267
  * the key of the leftmost node if the comparison result is greater than, and the key of the
287
268
  * rightmost node otherwise. If no node is found, it returns 0.
288
269
  */
289
- lastKey(beginRoot?: KeyOrNodeOrEntry<K, V, N>): K | undefined;
270
+ lastKey(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>): K | undefined;
290
271
  /**
291
272
  * Time Complexity: O(log n)
292
273
  * Space Complexity: O(log n)
293
- * Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key. Space for the recursive call stack in the worst case.
294
274
  */
295
275
  /**
296
276
  * Time Complexity: O(log n)
@@ -300,12 +280,12 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
300
280
  * are either lesser or greater than a target node, depending on the specified comparison type.
301
281
  * @param {C} callback - The `callback` parameter is a function that will be called for each node
302
282
  * that satisfies the condition specified by the `lesserOrGreater` parameter. It takes a single
303
- * parameter of type `N` (the node type) and returns a value of any type.
283
+ * parameter of type `NODE` (the node type) and returns a value of any type.
304
284
  * @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
305
285
  * traverse nodes that are lesser than, greater than, or equal to the `targetNode`. It is of type
306
286
  * `CP`, which is a custom type representing the comparison operator. The possible values for
307
287
  * `lesserOrGreater` are
308
- * @param {K | N | undefined} targetNode - The `targetNode` parameter represents the node in the
288
+ * @param {K | NODE | undefined} targetNode - The `targetNode` parameter represents the node in the
309
289
  * binary tree that you want to traverse from. It can be specified either by its key, by the node
310
290
  * object itself, or it can be left undefined to start the traversal from the root of the tree.
311
291
  * @param iterationType - The `iterationType` parameter determines the type of traversal to be
@@ -313,7 +293,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
313
293
  * @returns The function `lesserOrGreaterTraverse` returns an array of values of type
314
294
  * `ReturnType<C>`, which is the return type of the callback function passed as an argument.
315
295
  */
316
- lesserOrGreaterTraverse<C extends BTNCallback<N>>(callback?: C, lesserOrGreater?: CP, targetNode?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): ReturnType<C>[];
296
+ lesserOrGreaterTraverse<C extends BTNCallback<NODE>>(callback?: C, lesserOrGreater?: CP, targetNode?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
317
297
  /**
318
298
  * Time Complexity: O(log n)
319
299
  * Space Complexity: O(log n)
@@ -340,8 +320,8 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
340
320
  * AVL Tree: AVL trees are well-suited for scenarios involving frequent searching, insertion, and deletion operations. Through rotation adjustments, AVL trees maintain their balance, ensuring average and worst-case time complexity of O(log n).
341
321
  */
342
322
  /**
343
- * Time Complexity: O(n) - Building a balanced tree from a sorted array.
344
- * Space Complexity: O(n) - Additional space is required for the sorted array.
323
+ * Time Complexity: O(n)
324
+ * Space Complexity: O(log n)
345
325
  */
346
326
  /**
347
327
  * Time Complexity: O(n)
@@ -353,7 +333,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
353
333
  * @returns a boolean value.
354
334
  */
355
335
  isAVLBalanced(iterationType?: IterationType): boolean;
356
- protected _setRoot(v: N | undefined): void;
336
+ protected _setRoot(v: NODE | undefined): void;
357
337
  /**
358
338
  * The function compares two values using a comparator function and returns whether the first value
359
339
  * is greater than, less than, or equal to the second value.
@@ -11,32 +11,18 @@ class BSTNode extends binary_tree_1.BinaryTreeNode {
11
11
  this._left = undefined;
12
12
  this._right = undefined;
13
13
  }
14
- /**
15
- * Get the left child node.
16
- */
17
14
  get left() {
18
15
  return this._left;
19
16
  }
20
- /**
21
- * Set the left child node.
22
- * @param {N | undefined} v - The left child node.
23
- */
24
17
  set left(v) {
25
18
  if (v) {
26
19
  v.parent = this;
27
20
  }
28
21
  this._left = v;
29
22
  }
30
- /**
31
- * Get the right child node.
32
- */
33
23
  get right() {
34
24
  return this._right;
35
25
  }
36
- /**
37
- * Set the right child node.
38
- * @param {N | undefined} v - The right child node.
39
- */
40
26
  set right(v) {
41
27
  if (v) {
42
28
  v.parent = this;
@@ -103,14 +89,14 @@ class BST extends binary_tree_1.BinaryTree {
103
89
  return new BST([], Object.assign({ iterationType: this.iterationType, variant: this.variant }, options));
104
90
  }
105
91
  /**
106
- * The function `exemplarToNode` takes an keyOrNodeOrEntry and returns a node if the keyOrNodeOrEntry is valid,
92
+ * The function `keyValueOrEntryToNode` takes an keyOrNodeOrEntry and returns a node if the keyOrNodeOrEntry is valid,
107
93
  * otherwise it returns undefined.
108
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`, where:
94
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`, where:
109
95
  * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
110
- * `exemplarToNode` function. It represents the value associated with the keyOrNodeOrEntry node.
111
- * @returns a node of type N or undefined.
96
+ * `keyValueOrEntryToNode` function. It represents the value associated with the keyOrNodeOrEntry node.
97
+ * @returns a node of type NODE or undefined.
112
98
  */
113
- exemplarToNode(keyOrNodeOrEntry, value) {
99
+ keyValueOrEntryToNode(keyOrNodeOrEntry, value) {
114
100
  let node;
115
101
  if (keyOrNodeOrEntry === null || keyOrNodeOrEntry === undefined) {
116
102
  return;
@@ -138,7 +124,6 @@ class BST extends binary_tree_1.BinaryTree {
138
124
  /**
139
125
  * Time Complexity: O(log n)
140
126
  * Space Complexity: O(log n)
141
- * Average case for a balanced tree. Space for the recursive call stack in the worst case.
142
127
  */
143
128
  /**
144
129
  * Time Complexity: O(log n)
@@ -146,11 +131,11 @@ class BST extends binary_tree_1.BinaryTree {
146
131
  *
147
132
  * The function `ensureNode` returns the node corresponding to the given key if it is a node key,
148
133
  * otherwise it returns the key itself.
149
- * @param {K | N | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `N`, or
134
+ * @param {K | NODE | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `NODE`, or
150
135
  * `undefined`.
151
136
  * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
152
137
  * type of iteration to be performed. It has a default value of `IterationType.ITERATIVE`.
153
- * @returns either a node object (N) or undefined.
138
+ * @returns either a node object (NODE) or undefined.
154
139
  */
155
140
  ensureNode(keyOrNodeOrEntry, iterationType = types_1.IterationType.ITERATIVE) {
156
141
  let res;
@@ -169,7 +154,7 @@ class BST extends binary_tree_1.BinaryTree {
169
154
  }
170
155
  /**
171
156
  * The function checks if an keyOrNodeOrEntry is an instance of BSTNode.
172
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V, N>`.
157
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V, NODE>`.
173
158
  * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the BSTNode class.
174
159
  */
175
160
  isNode(keyOrNodeOrEntry) {
@@ -178,7 +163,6 @@ class BST extends binary_tree_1.BinaryTree {
178
163
  /**
179
164
  * Time Complexity: O(log n)
180
165
  * Space Complexity: O(1)
181
- * - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
182
166
  */
183
167
  /**
184
168
  * Time Complexity: O(log n)
@@ -193,7 +177,7 @@ class BST extends binary_tree_1.BinaryTree {
193
177
  * node was not added.
194
178
  */
195
179
  add(keyOrNodeOrEntry, value) {
196
- const newNode = this.exemplarToNode(keyOrNodeOrEntry, value);
180
+ const newNode = this.keyValueOrEntryToNode(keyOrNodeOrEntry, value);
197
181
  if (newNode === undefined)
198
182
  return false;
199
183
  if (this.root === undefined) {
@@ -217,7 +201,6 @@ class BST extends binary_tree_1.BinaryTree {
217
201
  else if (this._compare(current.key, newNode.key) === types_1.CP.gt) {
218
202
  if (current.left === undefined) {
219
203
  current.left = newNode;
220
- newNode.parent = current;
221
204
  this._size++;
222
205
  return true;
223
206
  }
@@ -226,7 +209,6 @@ class BST extends binary_tree_1.BinaryTree {
226
209
  else {
227
210
  if (current.right === undefined) {
228
211
  current.right = newNode;
229
- newNode.parent = current;
230
212
  this._size++;
231
213
  return true;
232
214
  }
@@ -237,12 +219,11 @@ class BST extends binary_tree_1.BinaryTree {
237
219
  }
238
220
  /**
239
221
  * Time Complexity: O(k log n)
240
- * Space Complexity: O(k)
241
- * Adding each element individually in a balanced tree. Additional space is required for the sorted array.
222
+ * Space Complexity: O(k + log n)
242
223
  */
243
224
  /**
244
225
  * Time Complexity: O(k log n)
245
- * Space Complexity: O(k)
226
+ * Space Complexity: O(k + log n)
246
227
  *
247
228
  * The `addMany` function in TypeScript adds multiple keys or nodes to a binary tree, optionally
248
229
  * balancing the tree after each addition.
@@ -258,7 +239,7 @@ class BST extends binary_tree_1.BinaryTree {
258
239
  * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
259
240
  * type of iteration to use when adding multiple keys or nodes. It has a default value of
260
241
  * `this.iterationType`, which suggests that it is a property of the current object.
261
- * @returns The function `addMany` returns an array of nodes (`N`) or `undefined` values.
242
+ * @returns The function `addMany` returns an array of nodes (`NODE`) or `undefined` values.
262
243
  */
263
244
  addMany(keysOrNodesOrEntries, values, isBalanceAdd = true, iterationType = this.iterationType) {
264
245
  const inserted = [];
@@ -349,7 +330,7 @@ class BST extends binary_tree_1.BinaryTree {
349
330
  * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
350
331
  * type of iteration to use when searching for a node in the binary tree. It can have two possible
351
332
  * values:
352
- * @returns The function `getNodeByKey` returns a node (`N`) if a node with the specified key is
333
+ * @returns The function `getNodeByKey` returns a node (`NODE`) if a node with the specified key is
353
334
  * found in the binary tree. If no node is found, it returns `undefined`.
354
335
  */
355
336
  getNodeByKey(key, iterationType = types_1.IterationType.ITERATIVE) {
@@ -385,32 +366,31 @@ class BST extends binary_tree_1.BinaryTree {
385
366
  }
386
367
  /**
387
368
  * Time Complexity: O(log n)
388
- * Space Complexity: O(log n)
389
- * Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key. Space for the recursive call stack in the worst case.
369
+ * Space Complexity: O(k + log n)
390
370
  * /
391
371
 
392
372
  /**
393
373
  * Time Complexity: O(log n)
394
- * Space Complexity: O(log n)
374
+ * Space Complexity: O(k + log n)
395
375
  *
396
376
  * The function `getNodes` returns an array of nodes that match a given identifier, using either a
397
377
  * recursive or iterative approach.
398
378
  * @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value that you
399
379
  * want to search for in the nodes of the binary tree. It can be of any type that is returned by the
400
380
  * callback function `C`.
401
- * @param {C} callback - The `callback` parameter is a function that takes a node of type `N` as its
381
+ * @param {C} callback - The `callback` parameter is a function that takes a node of type `NODE` as its
402
382
  * argument and returns a value of type `ReturnType<C>`. The `C` type parameter represents a callback
403
- * function type that extends the `BTNCallback<N>` type. The `BTNCallback<N>` type is
383
+ * function type that extends the `BTNCallback<NODE>` type. The `BTNCallback<NODE>` type is
404
384
  * @param [onlyOne=false] - A boolean flag indicating whether to stop searching after finding the
405
385
  * first node that matches the identifier. If set to true, the function will return an array
406
386
  * containing only the first matching node. If set to false (default), the function will continue
407
387
  * searching for all nodes that match the identifier and return an array containing
408
- * @param {K | N | undefined} beginRoot - The `beginRoot` parameter represents the starting node
388
+ * @param {K | NODE | undefined} beginRoot - The `beginRoot` parameter represents the starting node
409
389
  * for the traversal. It can be either a key value or a node object. If it is undefined, the
410
390
  * traversal will start from the root of the tree.
411
391
  * @param iterationType - The `iterationType` parameter determines the type of iteration to be
412
392
  * performed on the binary tree. It can have two possible values:
413
- * @returns The method returns an array of nodes (`N[]`).
393
+ * @returns The method returns an array of nodes (`NODE[]`).
414
394
  */
415
395
  getNodes(identifier, callback = this._defaultOneParamCallback, onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {
416
396
  beginRoot = this.ensureNode(beginRoot);
@@ -468,25 +448,6 @@ class BST extends binary_tree_1.BinaryTree {
468
448
  }
469
449
  return ans;
470
450
  }
471
- // /**
472
- // * The function overrides the subTreeTraverse method and returns the result of calling the super
473
- // * method with the provided arguments.
474
- // * @param {C} callback - The `callback` parameter is a function that will be called for each node in
475
- // * the subtree traversal. It should accept a single parameter of type `N`, which represents a node in
476
- // * the tree. The return type of the callback function can be any type.
477
- // * @param beginRoot - The `beginRoot` parameter is the starting point for traversing the subtree. It
478
- // * can be either a key, a node, or an entry.
479
- // * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
480
- // * be performed during the traversal of the subtree. It can have one of the following values:
481
- // * @returns The method is returning an array of the return type of the callback function.
482
- // */
483
- // override subTreeTraverse<C extends BTNCallback<N>>(
484
- // callback: C = this._defaultOneParamCallback as C,
485
- // beginRoot: KeyOrNodeOrEntry<K, V, N> = this.root,
486
- // iterationType = this.iterationType
487
- // ): ReturnType<C>[] {
488
- // return super.subTreeTraverse(callback, beginRoot, iterationType, false);
489
- // }
490
451
  /**
491
452
  * Time complexity: O(n)
492
453
  * Space complexity: O(n)
@@ -548,7 +509,7 @@ class BST extends binary_tree_1.BinaryTree {
548
509
  * The function overrides the listLevels method and returns an array of arrays containing the return
549
510
  * type of the callback function for each level of the tree.
550
511
  * @param {C} callback - The `callback` parameter is a generic type `C` that extends
551
- * `BTNCallback<N>`. It represents a callback function that will be called for each node in the tree
512
+ * `BTNCallback<NODE>`. It represents a callback function that will be called for each node in the tree
552
513
  * during the level listing process.
553
514
  * @param beginRoot - The `beginRoot` parameter is used to specify the starting point for listing the
554
515
  * levels of a binary tree. It can be either a key, a node, or an entry in the binary tree. If not
@@ -563,18 +524,17 @@ class BST extends binary_tree_1.BinaryTree {
563
524
  return super.listLevels(callback, beginRoot, iterationType, false);
564
525
  }
565
526
  /**
566
- * Time Complexity: O(n log n)
567
- * Space Complexity: O(n)
568
- * Adding each element individually in a balanced tree. Additional space is required for the sorted array.
527
+ * Time Complexity: O(log n)
528
+ * Space Complexity: O(1)
569
529
  */
570
530
  /**
571
- * Time Complexity: O(n log n)
572
- * Space Complexity: O(n)
531
+ * Time Complexity: O(log n)
532
+ * Space Complexity: O(1)
573
533
  *
574
534
  * The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
575
535
  * leftmost node if the comparison result is greater than.
576
- * @param {K | N | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
577
- * type `K`, `N`, or `undefined`. It represents the starting point for finding the last key in
536
+ * @param {K | NODE | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
537
+ * type `K`, `NODE`, or `undefined`. It represents the starting point for finding the last key in
578
538
  * the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).
579
539
  * @returns the key of the rightmost node in the binary tree if the comparison result is less than,
580
540
  * the key of the leftmost node if the comparison result is greater than, and the key of the
@@ -601,7 +561,6 @@ class BST extends binary_tree_1.BinaryTree {
601
561
  /**
602
562
  * Time Complexity: O(log n)
603
563
  * Space Complexity: O(log n)
604
- * Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key. Space for the recursive call stack in the worst case.
605
564
  */
606
565
  /**
607
566
  * Time Complexity: O(log n)
@@ -611,12 +570,12 @@ class BST extends binary_tree_1.BinaryTree {
611
570
  * are either lesser or greater than a target node, depending on the specified comparison type.
612
571
  * @param {C} callback - The `callback` parameter is a function that will be called for each node
613
572
  * that satisfies the condition specified by the `lesserOrGreater` parameter. It takes a single
614
- * parameter of type `N` (the node type) and returns a value of any type.
573
+ * parameter of type `NODE` (the node type) and returns a value of any type.
615
574
  * @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
616
575
  * traverse nodes that are lesser than, greater than, or equal to the `targetNode`. It is of type
617
576
  * `CP`, which is a custom type representing the comparison operator. The possible values for
618
577
  * `lesserOrGreater` are
619
- * @param {K | N | undefined} targetNode - The `targetNode` parameter represents the node in the
578
+ * @param {K | NODE | undefined} targetNode - The `targetNode` parameter represents the node in the
620
579
  * binary tree that you want to traverse from. It can be specified either by its key, by the node
621
580
  * object itself, or it can be left undefined to start the traversal from the root of the tree.
622
581
  * @param iterationType - The `iterationType` parameter determines the type of traversal to be
@@ -725,8 +684,8 @@ class BST extends binary_tree_1.BinaryTree {
725
684
  * AVL Tree: AVL trees are well-suited for scenarios involving frequent searching, insertion, and deletion operations. Through rotation adjustments, AVL trees maintain their balance, ensuring average and worst-case time complexity of O(log n).
726
685
  */
727
686
  /**
728
- * Time Complexity: O(n) - Building a balanced tree from a sorted array.
729
- * Space Complexity: O(n) - Additional space is required for the sorted array.
687
+ * Time Complexity: O(n)
688
+ * Space Complexity: O(log n)
730
689
  */
731
690
  /**
732
691
  * Time Complexity: O(n)