data-structure-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 (156) hide show
  1. package/CHANGELOG.md +2 -1
  2. package/README.md +204 -212
  3. package/benchmark/report.html +37 -1
  4. package/benchmark/report.json +370 -22
  5. package/dist/cjs/data-structures/base/iterable-base.d.ts +114 -9
  6. package/dist/cjs/data-structures/base/iterable-base.js +143 -7
  7. package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +43 -46
  9. package/dist/cjs/data-structures/binary-tree/avl-tree.js +68 -71
  10. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +244 -199
  12. package/dist/cjs/data-structures/binary-tree/binary-tree.js +484 -376
  13. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/bst.d.ts +54 -74
  15. package/dist/cjs/data-structures/binary-tree/bst.js +30 -71
  16. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +78 -60
  18. package/dist/cjs/data-structures/binary-tree/rb-tree.js +84 -89
  19. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  20. package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +37 -56
  21. package/dist/cjs/data-structures/binary-tree/tree-multimap.js +64 -85
  22. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  23. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +1 -0
  24. package/dist/cjs/data-structures/graph/abstract-graph.js +3 -0
  25. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  26. package/dist/cjs/data-structures/graph/directed-graph.d.ts +14 -0
  27. package/dist/cjs/data-structures/graph/directed-graph.js +26 -0
  28. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  29. package/dist/cjs/data-structures/graph/map-graph.d.ts +8 -0
  30. package/dist/cjs/data-structures/graph/map-graph.js +14 -0
  31. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  32. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +16 -0
  33. package/dist/cjs/data-structures/graph/undirected-graph.js +25 -0
  34. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  35. package/dist/cjs/data-structures/hash/hash-map.d.ts +121 -15
  36. package/dist/cjs/data-structures/hash/hash-map.js +160 -25
  37. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  38. package/dist/cjs/data-structures/heap/heap.d.ts +66 -6
  39. package/dist/cjs/data-structures/heap/heap.js +66 -6
  40. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  41. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +67 -50
  42. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +70 -64
  43. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  44. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +128 -103
  45. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +130 -112
  46. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  47. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +63 -36
  48. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +63 -36
  49. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  50. package/dist/cjs/data-structures/matrix/matrix.d.ts +35 -4
  51. package/dist/cjs/data-structures/matrix/matrix.js +50 -11
  52. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  53. package/dist/cjs/data-structures/queue/deque.d.ts +49 -19
  54. package/dist/cjs/data-structures/queue/deque.js +101 -47
  55. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  56. package/dist/cjs/data-structures/queue/queue.d.ts +39 -5
  57. package/dist/cjs/data-structures/queue/queue.js +47 -5
  58. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  59. package/dist/cjs/data-structures/stack/stack.d.ts +16 -0
  60. package/dist/cjs/data-structures/stack/stack.js +22 -0
  61. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  62. package/dist/cjs/data-structures/trie/trie.d.ts +38 -1
  63. package/dist/cjs/data-structures/trie/trie.js +41 -0
  64. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  65. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  66. package/dist/cjs/types/data-structures/hash/hash-map.d.ts +4 -3
  67. package/dist/cjs/types/utils/utils.d.ts +1 -0
  68. package/dist/mjs/data-structures/base/iterable-base.d.ts +114 -9
  69. package/dist/mjs/data-structures/base/iterable-base.js +143 -7
  70. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +43 -46
  71. package/dist/mjs/data-structures/binary-tree/avl-tree.js +68 -71
  72. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +244 -199
  73. package/dist/mjs/data-structures/binary-tree/binary-tree.js +483 -375
  74. package/dist/mjs/data-structures/binary-tree/bst.d.ts +54 -74
  75. package/dist/mjs/data-structures/binary-tree/bst.js +30 -71
  76. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +78 -60
  77. package/dist/mjs/data-structures/binary-tree/rb-tree.js +84 -89
  78. package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +37 -56
  79. package/dist/mjs/data-structures/binary-tree/tree-multimap.js +64 -85
  80. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +1 -0
  81. package/dist/mjs/data-structures/graph/abstract-graph.js +3 -0
  82. package/dist/mjs/data-structures/graph/directed-graph.d.ts +14 -0
  83. package/dist/mjs/data-structures/graph/directed-graph.js +26 -0
  84. package/dist/mjs/data-structures/graph/map-graph.d.ts +8 -0
  85. package/dist/mjs/data-structures/graph/map-graph.js +14 -0
  86. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +16 -0
  87. package/dist/mjs/data-structures/graph/undirected-graph.js +25 -0
  88. package/dist/mjs/data-structures/hash/hash-map.d.ts +121 -15
  89. package/dist/mjs/data-structures/hash/hash-map.js +160 -25
  90. package/dist/mjs/data-structures/heap/heap.d.ts +66 -6
  91. package/dist/mjs/data-structures/heap/heap.js +66 -6
  92. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +67 -50
  93. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +70 -64
  94. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +128 -103
  95. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +130 -112
  96. package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +63 -36
  97. package/dist/mjs/data-structures/linked-list/skip-linked-list.js +63 -36
  98. package/dist/mjs/data-structures/matrix/matrix.d.ts +35 -4
  99. package/dist/mjs/data-structures/matrix/matrix.js +50 -11
  100. package/dist/mjs/data-structures/queue/deque.d.ts +49 -19
  101. package/dist/mjs/data-structures/queue/deque.js +101 -47
  102. package/dist/mjs/data-structures/queue/queue.d.ts +39 -5
  103. package/dist/mjs/data-structures/queue/queue.js +47 -5
  104. package/dist/mjs/data-structures/stack/stack.d.ts +16 -0
  105. package/dist/mjs/data-structures/stack/stack.js +22 -0
  106. package/dist/mjs/data-structures/trie/trie.d.ts +38 -1
  107. package/dist/mjs/data-structures/trie/trie.js +41 -0
  108. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  109. package/dist/mjs/types/data-structures/hash/hash-map.d.ts +4 -3
  110. package/dist/mjs/types/utils/utils.d.ts +1 -0
  111. package/dist/umd/data-structure-typed.js +1730 -1042
  112. package/dist/umd/data-structure-typed.min.js +3 -3
  113. package/dist/umd/data-structure-typed.min.js.map +1 -1
  114. package/package.json +16 -40
  115. package/src/data-structures/base/iterable-base.ts +172 -19
  116. package/src/data-structures/binary-tree/avl-tree.ts +97 -97
  117. package/src/data-structures/binary-tree/binary-tree.ts +674 -671
  118. package/src/data-structures/binary-tree/bst.ts +89 -131
  119. package/src/data-structures/binary-tree/rb-tree.ts +127 -155
  120. package/src/data-structures/binary-tree/tree-multimap.ts +96 -112
  121. package/src/data-structures/graph/abstract-graph.ts +4 -0
  122. package/src/data-structures/graph/directed-graph.ts +30 -0
  123. package/src/data-structures/graph/map-graph.ts +15 -0
  124. package/src/data-structures/graph/undirected-graph.ts +28 -0
  125. package/src/data-structures/hash/hash-map.ts +175 -34
  126. package/src/data-structures/heap/heap.ts +66 -6
  127. package/src/data-structures/linked-list/doubly-linked-list.ts +72 -66
  128. package/src/data-structures/linked-list/singly-linked-list.ts +132 -114
  129. package/src/data-structures/linked-list/skip-linked-list.ts +63 -37
  130. package/src/data-structures/matrix/matrix.ts +52 -12
  131. package/src/data-structures/queue/deque.ts +108 -49
  132. package/src/data-structures/queue/queue.ts +51 -5
  133. package/src/data-structures/stack/stack.ts +24 -0
  134. package/src/data-structures/trie/trie.ts +45 -1
  135. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  136. package/src/types/data-structures/hash/hash-map.ts +4 -3
  137. package/src/types/utils/utils.ts +2 -0
  138. package/test/performance/data-structures/graph/directed-graph.test.ts +3 -3
  139. package/test/performance/data-structures/queue/deque.test.ts +26 -25
  140. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +37 -0
  141. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +46 -17
  142. package/test/unit/data-structures/binary-tree/bst.test.ts +65 -1
  143. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +38 -1
  144. package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +37 -32
  145. package/test/unit/data-structures/graph/abstract-graph.test.ts +8 -0
  146. package/test/unit/data-structures/graph/directed-graph.test.ts +249 -0
  147. package/test/unit/data-structures/hash/hash-map.test.ts +376 -353
  148. package/test/unit/data-structures/heap/heap.test.ts +18 -1
  149. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +24 -5
  150. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +20 -2
  151. package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
  152. package/test/unit/data-structures/queue/deque.test.ts +71 -10
  153. package/test/unit/data-structures/queue/queue.test.ts +23 -6
  154. package/test/unit/data-structures/stack/stack.test.ts +17 -0
  155. package/test/unit/data-structures/trie/trie.test.ts +17 -0
  156. package/test/unit/unrestricted-interconversion.test.ts +143 -10
@@ -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.
@@ -10,16 +10,9 @@ export class BSTNode extends BinaryTreeNode {
10
10
  this._right = undefined;
11
11
  }
12
12
  _left;
13
- /**
14
- * Get the left child node.
15
- */
16
13
  get left() {
17
14
  return this._left;
18
15
  }
19
- /**
20
- * Set the left child node.
21
- * @param {N | undefined} v - The left child node.
22
- */
23
16
  set left(v) {
24
17
  if (v) {
25
18
  v.parent = this;
@@ -27,16 +20,9 @@ export class BSTNode extends BinaryTreeNode {
27
20
  this._left = v;
28
21
  }
29
22
  _right;
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;
@@ -107,14 +93,14 @@ export class BST extends BinaryTree {
107
93
  });
108
94
  }
109
95
  /**
110
- * The function `exemplarToNode` takes an keyOrNodeOrEntry and returns a node if the keyOrNodeOrEntry is valid,
96
+ * The function `keyValueOrEntryToNode` takes an keyOrNodeOrEntry and returns a node if the keyOrNodeOrEntry is valid,
111
97
  * otherwise it returns undefined.
112
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`, where:
98
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`, where:
113
99
  * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
114
- * `exemplarToNode` function. It represents the value associated with the keyOrNodeOrEntry node.
115
- * @returns a node of type N or undefined.
100
+ * `keyValueOrEntryToNode` function. It represents the value associated with the keyOrNodeOrEntry node.
101
+ * @returns a node of type NODE or undefined.
116
102
  */
117
- exemplarToNode(keyOrNodeOrEntry, value) {
103
+ keyValueOrEntryToNode(keyOrNodeOrEntry, value) {
118
104
  let node;
119
105
  if (keyOrNodeOrEntry === null || keyOrNodeOrEntry === undefined) {
120
106
  return;
@@ -142,7 +128,6 @@ export class BST extends BinaryTree {
142
128
  /**
143
129
  * Time Complexity: O(log n)
144
130
  * Space Complexity: O(log n)
145
- * Average case for a balanced tree. Space for the recursive call stack in the worst case.
146
131
  */
147
132
  /**
148
133
  * Time Complexity: O(log n)
@@ -150,11 +135,11 @@ export class BST extends BinaryTree {
150
135
  *
151
136
  * The function `ensureNode` returns the node corresponding to the given key if it is a node key,
152
137
  * otherwise it returns the key itself.
153
- * @param {K | N | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `N`, or
138
+ * @param {K | NODE | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `NODE`, or
154
139
  * `undefined`.
155
140
  * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
156
141
  * type of iteration to be performed. It has a default value of `IterationType.ITERATIVE`.
157
- * @returns either a node object (N) or undefined.
142
+ * @returns either a node object (NODE) or undefined.
158
143
  */
159
144
  ensureNode(keyOrNodeOrEntry, iterationType = IterationType.ITERATIVE) {
160
145
  let res;
@@ -173,7 +158,7 @@ export class BST extends BinaryTree {
173
158
  }
174
159
  /**
175
160
  * The function checks if an keyOrNodeOrEntry is an instance of BSTNode.
176
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V, N>`.
161
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V, NODE>`.
177
162
  * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the BSTNode class.
178
163
  */
179
164
  isNode(keyOrNodeOrEntry) {
@@ -182,7 +167,6 @@ export class BST extends BinaryTree {
182
167
  /**
183
168
  * Time Complexity: O(log n)
184
169
  * Space Complexity: O(1)
185
- * - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
186
170
  */
187
171
  /**
188
172
  * Time Complexity: O(log n)
@@ -197,7 +181,7 @@ export class BST extends BinaryTree {
197
181
  * node was not added.
198
182
  */
199
183
  add(keyOrNodeOrEntry, value) {
200
- const newNode = this.exemplarToNode(keyOrNodeOrEntry, value);
184
+ const newNode = this.keyValueOrEntryToNode(keyOrNodeOrEntry, value);
201
185
  if (newNode === undefined)
202
186
  return false;
203
187
  if (this.root === undefined) {
@@ -221,7 +205,6 @@ export class BST extends BinaryTree {
221
205
  else if (this._compare(current.key, newNode.key) === CP.gt) {
222
206
  if (current.left === undefined) {
223
207
  current.left = newNode;
224
- newNode.parent = current;
225
208
  this._size++;
226
209
  return true;
227
210
  }
@@ -230,7 +213,6 @@ export class BST extends BinaryTree {
230
213
  else {
231
214
  if (current.right === undefined) {
232
215
  current.right = newNode;
233
- newNode.parent = current;
234
216
  this._size++;
235
217
  return true;
236
218
  }
@@ -241,12 +223,11 @@ export class BST extends BinaryTree {
241
223
  }
242
224
  /**
243
225
  * Time Complexity: O(k log n)
244
- * Space Complexity: O(k)
245
- * Adding each element individually in a balanced tree. Additional space is required for the sorted array.
226
+ * Space Complexity: O(k + log n)
246
227
  */
247
228
  /**
248
229
  * Time Complexity: O(k log n)
249
- * Space Complexity: O(k)
230
+ * Space Complexity: O(k + log n)
250
231
  *
251
232
  * The `addMany` function in TypeScript adds multiple keys or nodes to a binary tree, optionally
252
233
  * balancing the tree after each addition.
@@ -262,7 +243,7 @@ export class BST extends BinaryTree {
262
243
  * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
263
244
  * type of iteration to use when adding multiple keys or nodes. It has a default value of
264
245
  * `this.iterationType`, which suggests that it is a property of the current object.
265
- * @returns The function `addMany` returns an array of nodes (`N`) or `undefined` values.
246
+ * @returns The function `addMany` returns an array of nodes (`NODE`) or `undefined` values.
266
247
  */
267
248
  addMany(keysOrNodesOrEntries, values, isBalanceAdd = true, iterationType = this.iterationType) {
268
249
  const inserted = [];
@@ -353,7 +334,7 @@ export class BST extends BinaryTree {
353
334
  * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
354
335
  * type of iteration to use when searching for a node in the binary tree. It can have two possible
355
336
  * values:
356
- * @returns The function `getNodeByKey` returns a node (`N`) if a node with the specified key is
337
+ * @returns The function `getNodeByKey` returns a node (`NODE`) if a node with the specified key is
357
338
  * found in the binary tree. If no node is found, it returns `undefined`.
358
339
  */
359
340
  getNodeByKey(key, iterationType = IterationType.ITERATIVE) {
@@ -389,32 +370,31 @@ export class BST extends BinaryTree {
389
370
  }
390
371
  /**
391
372
  * Time Complexity: O(log n)
392
- * Space Complexity: O(log n)
393
- * 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.
373
+ * Space Complexity: O(k + log n)
394
374
  * /
395
375
 
396
376
  /**
397
377
  * Time Complexity: O(log n)
398
- * Space Complexity: O(log n)
378
+ * Space Complexity: O(k + log n)
399
379
  *
400
380
  * The function `getNodes` returns an array of nodes that match a given identifier, using either a
401
381
  * recursive or iterative approach.
402
382
  * @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value that you
403
383
  * want to search for in the nodes of the binary tree. It can be of any type that is returned by the
404
384
  * callback function `C`.
405
- * @param {C} callback - The `callback` parameter is a function that takes a node of type `N` as its
385
+ * @param {C} callback - The `callback` parameter is a function that takes a node of type `NODE` as its
406
386
  * argument and returns a value of type `ReturnType<C>`. The `C` type parameter represents a callback
407
- * function type that extends the `BTNCallback<N>` type. The `BTNCallback<N>` type is
387
+ * function type that extends the `BTNCallback<NODE>` type. The `BTNCallback<NODE>` type is
408
388
  * @param [onlyOne=false] - A boolean flag indicating whether to stop searching after finding the
409
389
  * first node that matches the identifier. If set to true, the function will return an array
410
390
  * containing only the first matching node. If set to false (default), the function will continue
411
391
  * searching for all nodes that match the identifier and return an array containing
412
- * @param {K | N | undefined} beginRoot - The `beginRoot` parameter represents the starting node
392
+ * @param {K | NODE | undefined} beginRoot - The `beginRoot` parameter represents the starting node
413
393
  * for the traversal. It can be either a key value or a node object. If it is undefined, the
414
394
  * traversal will start from the root of the tree.
415
395
  * @param iterationType - The `iterationType` parameter determines the type of iteration to be
416
396
  * performed on the binary tree. It can have two possible values:
417
- * @returns The method returns an array of nodes (`N[]`).
397
+ * @returns The method returns an array of nodes (`NODE[]`).
418
398
  */
419
399
  getNodes(identifier, callback = this._defaultOneParamCallback, onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {
420
400
  beginRoot = this.ensureNode(beginRoot);
@@ -472,25 +452,6 @@ export class BST extends BinaryTree {
472
452
  }
473
453
  return ans;
474
454
  }
475
- // /**
476
- // * The function overrides the subTreeTraverse method and returns the result of calling the super
477
- // * method with the provided arguments.
478
- // * @param {C} callback - The `callback` parameter is a function that will be called for each node in
479
- // * the subtree traversal. It should accept a single parameter of type `N`, which represents a node in
480
- // * the tree. The return type of the callback function can be any type.
481
- // * @param beginRoot - The `beginRoot` parameter is the starting point for traversing the subtree. It
482
- // * can be either a key, a node, or an entry.
483
- // * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
484
- // * be performed during the traversal of the subtree. It can have one of the following values:
485
- // * @returns The method is returning an array of the return type of the callback function.
486
- // */
487
- // override subTreeTraverse<C extends BTNCallback<N>>(
488
- // callback: C = this._defaultOneParamCallback as C,
489
- // beginRoot: KeyOrNodeOrEntry<K, V, N> = this.root,
490
- // iterationType = this.iterationType
491
- // ): ReturnType<C>[] {
492
- // return super.subTreeTraverse(callback, beginRoot, iterationType, false);
493
- // }
494
455
  /**
495
456
  * Time complexity: O(n)
496
457
  * Space complexity: O(n)
@@ -552,7 +513,7 @@ export class BST extends BinaryTree {
552
513
  * The function overrides the listLevels method and returns an array of arrays containing the return
553
514
  * type of the callback function for each level of the tree.
554
515
  * @param {C} callback - The `callback` parameter is a generic type `C` that extends
555
- * `BTNCallback<N>`. It represents a callback function that will be called for each node in the tree
516
+ * `BTNCallback<NODE>`. It represents a callback function that will be called for each node in the tree
556
517
  * during the level listing process.
557
518
  * @param beginRoot - The `beginRoot` parameter is used to specify the starting point for listing the
558
519
  * levels of a binary tree. It can be either a key, a node, or an entry in the binary tree. If not
@@ -567,18 +528,17 @@ export class BST extends BinaryTree {
567
528
  return super.listLevels(callback, beginRoot, iterationType, false);
568
529
  }
569
530
  /**
570
- * Time Complexity: O(n log n)
571
- * Space Complexity: O(n)
572
- * Adding each element individually in a balanced tree. Additional space is required for the sorted array.
531
+ * Time Complexity: O(log n)
532
+ * Space Complexity: O(1)
573
533
  */
574
534
  /**
575
- * Time Complexity: O(n log n)
576
- * Space Complexity: O(n)
535
+ * Time Complexity: O(log n)
536
+ * Space Complexity: O(1)
577
537
  *
578
538
  * The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
579
539
  * leftmost node if the comparison result is greater than.
580
- * @param {K | N | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
581
- * type `K`, `N`, or `undefined`. It represents the starting point for finding the last key in
540
+ * @param {K | NODE | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
541
+ * type `K`, `NODE`, or `undefined`. It represents the starting point for finding the last key in
582
542
  * the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).
583
543
  * @returns the key of the rightmost node in the binary tree if the comparison result is less than,
584
544
  * the key of the leftmost node if the comparison result is greater than, and the key of the
@@ -605,7 +565,6 @@ export class BST extends BinaryTree {
605
565
  /**
606
566
  * Time Complexity: O(log n)
607
567
  * Space Complexity: O(log n)
608
- * 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.
609
568
  */
610
569
  /**
611
570
  * Time Complexity: O(log n)
@@ -615,12 +574,12 @@ export class BST extends BinaryTree {
615
574
  * are either lesser or greater than a target node, depending on the specified comparison type.
616
575
  * @param {C} callback - The `callback` parameter is a function that will be called for each node
617
576
  * that satisfies the condition specified by the `lesserOrGreater` parameter. It takes a single
618
- * parameter of type `N` (the node type) and returns a value of any type.
577
+ * parameter of type `NODE` (the node type) and returns a value of any type.
619
578
  * @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
620
579
  * traverse nodes that are lesser than, greater than, or equal to the `targetNode`. It is of type
621
580
  * `CP`, which is a custom type representing the comparison operator. The possible values for
622
581
  * `lesserOrGreater` are
623
- * @param {K | N | undefined} targetNode - The `targetNode` parameter represents the node in the
582
+ * @param {K | NODE | undefined} targetNode - The `targetNode` parameter represents the node in the
624
583
  * binary tree that you want to traverse from. It can be specified either by its key, by the node
625
584
  * object itself, or it can be left undefined to start the traversal from the root of the tree.
626
585
  * @param iterationType - The `iterationType` parameter determines the type of traversal to be
@@ -729,8 +688,8 @@ export class BST extends BinaryTree {
729
688
  * 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).
730
689
  */
731
690
  /**
732
- * Time Complexity: O(n) - Building a balanced tree from a sorted array.
733
- * Space Complexity: O(n) - Additional space is required for the sorted array.
691
+ * Time Complexity: O(n)
692
+ * Space Complexity: O(log n)
734
693
  */
735
694
  /**
736
695
  * Time Complexity: O(n)