data-structure-typed 1.49.4 → 1.49.6

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 (186) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +15 -26
  3. package/README_zh-CN.md +1 -1
  4. package/benchmark/report.html +14 -23
  5. package/benchmark/report.json +163 -256
  6. package/dist/cjs/data-structures/base/iterable-base.d.ts +1 -1
  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 +53 -48
  9. package/dist/cjs/data-structures/binary-tree/avl-tree.js +55 -49
  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 +154 -143
  12. package/dist/cjs/data-structures/binary-tree/binary-tree.js +211 -198
  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 +83 -71
  15. package/dist/cjs/data-structures/binary-tree/bst.js +113 -89
  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 +37 -35
  18. package/dist/cjs/data-structures/binary-tree/rb-tree.js +62 -59
  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 +46 -55
  21. package/dist/cjs/data-structures/binary-tree/tree-multimap.js +59 -94
  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 -1
  24. package/dist/cjs/data-structures/graph/abstract-graph.js +3 -2
  25. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  26. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  27. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  28. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  29. package/dist/cjs/data-structures/hash/hash-map.d.ts +1 -1
  30. package/dist/cjs/data-structures/hash/hash-map.js +2 -2
  31. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  32. package/dist/cjs/data-structures/heap/heap.js +2 -3
  33. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  34. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  35. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  36. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  37. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  38. package/dist/cjs/data-structures/matrix/index.d.ts +0 -2
  39. package/dist/cjs/data-structures/matrix/index.js +0 -2
  40. package/dist/cjs/data-structures/matrix/index.js.map +1 -1
  41. package/dist/cjs/data-structures/matrix/matrix.d.ts +128 -10
  42. package/dist/cjs/data-structures/matrix/matrix.js +400 -15
  43. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  44. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  45. package/dist/cjs/data-structures/queue/deque.d.ts +2 -2
  46. package/dist/cjs/data-structures/queue/deque.js +5 -7
  47. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  48. package/dist/cjs/data-structures/queue/queue.d.ts +1 -1
  49. package/dist/cjs/interfaces/binary-tree.d.ts +3 -3
  50. package/dist/cjs/types/common.d.ts +3 -3
  51. package/dist/cjs/types/common.js +2 -2
  52. package/dist/cjs/types/common.js.map +1 -1
  53. package/dist/cjs/types/data-structures/base/base.d.ts +1 -1
  54. package/dist/cjs/types/data-structures/heap/heap.d.ts +1 -1
  55. package/dist/cjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  56. package/dist/cjs/utils/utils.d.ts +1 -0
  57. package/dist/cjs/utils/utils.js +6 -1
  58. package/dist/cjs/utils/utils.js.map +1 -1
  59. package/dist/mjs/data-structures/base/iterable-base.d.ts +1 -1
  60. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +53 -48
  61. package/dist/mjs/data-structures/binary-tree/avl-tree.js +57 -50
  62. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +154 -143
  63. package/dist/mjs/data-structures/binary-tree/binary-tree.js +212 -199
  64. package/dist/mjs/data-structures/binary-tree/bst.d.ts +83 -71
  65. package/dist/mjs/data-structures/binary-tree/bst.js +115 -90
  66. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +37 -35
  67. package/dist/mjs/data-structures/binary-tree/rb-tree.js +64 -60
  68. package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +46 -55
  69. package/dist/mjs/data-structures/binary-tree/tree-multimap.js +61 -95
  70. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +1 -1
  71. package/dist/mjs/data-structures/graph/abstract-graph.js +4 -3
  72. package/dist/mjs/data-structures/hash/hash-map.d.ts +1 -1
  73. package/dist/mjs/data-structures/hash/hash-map.js +2 -2
  74. package/dist/mjs/data-structures/heap/heap.js +2 -3
  75. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  76. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +1 -1
  77. package/dist/mjs/data-structures/matrix/index.d.ts +0 -2
  78. package/dist/mjs/data-structures/matrix/index.js +0 -2
  79. package/dist/mjs/data-structures/matrix/matrix.d.ts +128 -10
  80. package/dist/mjs/data-structures/matrix/matrix.js +399 -16
  81. package/dist/mjs/data-structures/queue/deque.d.ts +2 -2
  82. package/dist/mjs/data-structures/queue/deque.js +7 -9
  83. package/dist/mjs/data-structures/queue/queue.d.ts +1 -1
  84. package/dist/mjs/data-structures/queue/queue.js +1 -1
  85. package/dist/mjs/interfaces/binary-tree.d.ts +3 -3
  86. package/dist/mjs/types/common.d.ts +3 -3
  87. package/dist/mjs/types/common.js +2 -2
  88. package/dist/mjs/types/data-structures/base/base.d.ts +1 -1
  89. package/dist/mjs/types/data-structures/heap/heap.d.ts +1 -1
  90. package/dist/mjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  91. package/dist/mjs/utils/utils.d.ts +1 -0
  92. package/dist/mjs/utils/utils.js +4 -0
  93. package/dist/umd/data-structure-typed.js +853 -943
  94. package/dist/umd/data-structure-typed.min.js +2 -2
  95. package/dist/umd/data-structure-typed.min.js.map +1 -1
  96. package/package.json +4 -3
  97. package/src/data-structures/base/index.ts +1 -1
  98. package/src/data-structures/base/iterable-base.ts +7 -10
  99. package/src/data-structures/binary-tree/avl-tree.ts +73 -61
  100. package/src/data-structures/binary-tree/binary-tree.ts +301 -270
  101. package/src/data-structures/binary-tree/bst.ts +139 -115
  102. package/src/data-structures/binary-tree/rb-tree.ts +81 -73
  103. package/src/data-structures/binary-tree/tree-multimap.ts +72 -103
  104. package/src/data-structures/graph/abstract-graph.ts +13 -11
  105. package/src/data-structures/graph/directed-graph.ts +1 -3
  106. package/src/data-structures/graph/map-graph.ts +6 -1
  107. package/src/data-structures/graph/undirected-graph.ts +3 -6
  108. package/src/data-structures/hash/hash-map.ts +18 -16
  109. package/src/data-structures/heap/heap.ts +7 -10
  110. package/src/data-structures/heap/max-heap.ts +2 -1
  111. package/src/data-structures/heap/min-heap.ts +2 -1
  112. package/src/data-structures/linked-list/singly-linked-list.ts +2 -3
  113. package/src/data-structures/matrix/index.ts +0 -2
  114. package/src/data-structures/matrix/matrix.ts +442 -13
  115. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -10
  116. package/src/data-structures/queue/deque.ts +18 -39
  117. package/src/data-structures/queue/queue.ts +1 -1
  118. package/src/interfaces/binary-tree.ts +9 -4
  119. package/src/types/common.ts +5 -5
  120. package/src/types/data-structures/base/base.ts +14 -3
  121. package/src/types/data-structures/base/index.ts +1 -1
  122. package/src/types/data-structures/graph/abstract-graph.ts +4 -2
  123. package/src/types/data-structures/hash/hash-map.ts +3 -3
  124. package/src/types/data-structures/heap/heap.ts +2 -2
  125. package/src/types/data-structures/priority-queue/priority-queue.ts +2 -2
  126. package/src/utils/utils.ts +7 -1
  127. package/test/integration/avl-tree.test.ts +18 -1
  128. package/test/integration/bst.test.ts +2 -2
  129. package/test/performance/data-structures/binary-tree/avl-tree.test.ts +4 -12
  130. package/test/performance/data-structures/binary-tree/binary-tree-overall.test.ts +37 -0
  131. package/test/performance/data-structures/binary-tree/binary-tree.test.ts +6 -16
  132. package/test/performance/data-structures/binary-tree/bst.test.ts +5 -13
  133. package/test/performance/data-structures/binary-tree/rb-tree.test.ts +6 -16
  134. package/test/performance/data-structures/comparison/comparison.test.ts +19 -47
  135. package/test/performance/data-structures/graph/directed-graph.test.ts +3 -14
  136. package/test/performance/data-structures/hash/hash-map.test.ts +14 -38
  137. package/test/performance/data-structures/heap/heap.test.ts +5 -18
  138. package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +0 -2
  139. package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +0 -2
  140. package/test/performance/data-structures/priority-queue/max-priority-queue.test.ts +2 -4
  141. package/test/performance/data-structures/priority-queue/priority-queue.test.ts +4 -14
  142. package/test/performance/data-structures/queue/deque.test.ts +6 -7
  143. package/test/performance/data-structures/queue/queue.test.ts +13 -29
  144. package/test/performance/data-structures/stack/stack.test.ts +6 -18
  145. package/test/performance/data-structures/trie/trie.test.ts +2 -6
  146. package/test/performance/reportor.ts +14 -15
  147. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +14 -3
  148. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +65 -29
  149. package/test/unit/data-structures/binary-tree/bst.test.ts +69 -27
  150. package/test/unit/data-structures/binary-tree/overall.test.ts +16 -18
  151. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +17 -6
  152. package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +37 -21
  153. package/test/unit/data-structures/graph/directed-graph.test.ts +104 -45
  154. package/test/unit/data-structures/graph/undirected-graph.test.ts +57 -40
  155. package/test/unit/data-structures/hash/hash-map.test.ts +48 -28
  156. package/test/unit/data-structures/hash/hash-table.test.ts +0 -4
  157. package/test/unit/data-structures/heap/heap.test.ts +0 -1
  158. package/test/unit/data-structures/heap/min-heap.test.ts +6 -5
  159. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +10 -11
  160. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +3 -4
  161. package/test/unit/data-structures/matrix/matrix.test.ts +345 -52
  162. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +1 -1
  163. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +0 -1
  164. package/test/unit/data-structures/queue/deque.test.ts +0 -6
  165. package/test/unit/data-structures/queue/queue.test.ts +1 -1
  166. package/test/unit/data-structures/stack/stack.test.ts +3 -4
  167. package/test/unit/unrestricted-interconversion.test.ts +50 -44
  168. package/test/utils/performanc.ts +1 -1
  169. package/typedoc.json +30 -0
  170. package/dist/cjs/data-structures/matrix/matrix2d.d.ts +0 -107
  171. package/dist/cjs/data-structures/matrix/matrix2d.js +0 -200
  172. package/dist/cjs/data-structures/matrix/matrix2d.js.map +0 -1
  173. package/dist/cjs/data-structures/matrix/vector2d.d.ts +0 -200
  174. package/dist/cjs/data-structures/matrix/vector2d.js +0 -291
  175. package/dist/cjs/data-structures/matrix/vector2d.js.map +0 -1
  176. package/dist/mjs/data-structures/matrix/matrix2d.d.ts +0 -107
  177. package/dist/mjs/data-structures/matrix/matrix2d.js +0 -196
  178. package/dist/mjs/data-structures/matrix/vector2d.d.ts +0 -200
  179. package/dist/mjs/data-structures/matrix/vector2d.js +0 -289
  180. package/src/data-structures/matrix/matrix2d.ts +0 -211
  181. package/src/data-structures/matrix/vector2d.ts +0 -315
  182. package/test/performance/data-structures/binary-tree/overall.test.ts +0 -0
  183. package/test/performance/data-structures/matrix/matrix2d.test.ts +0 -0
  184. package/test/performance/data-structures/matrix/vector2d.test.ts +0 -0
  185. package/test/unit/data-structures/matrix/matrix2d.test.ts +0 -345
  186. package/test/unit/data-structures/matrix/vector2d.test.ts +0 -171
@@ -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 { BSTNested, BSTNKeyOrNode, BSTNodeNested, BSTOptions, BTNCallback, BTNExemplar, BTNKeyOrNode } from '../../types';
8
+ import type { BSTNested, BSTNodeNested, BSTOptions, BTNCallback, KeyOrNodeOrEntry } from '../../types';
9
9
  import { BSTVariant, CP, IterationType } from '../../types';
10
10
  import { BinaryTree, BinaryTreeNode } from './binary-tree';
11
11
  import { IBinaryTree } from '../../interfaces';
@@ -45,13 +45,13 @@ export declare class BSTNode<K = any, V = any, N extends BSTNode<K, V, N> = BSTN
45
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> {
46
46
  /**
47
47
  * This is the constructor function for a binary search tree class in TypeScript, which initializes
48
- * the tree with optional elements and options.
49
- * @param [elements] - An optional iterable of BTNExemplar objects that will be added to the
48
+ * the tree with optional nodes and options.
49
+ * @param [nodes] - An optional iterable of KeyOrNodeOrEntry objects that will be added to the
50
50
  * binary search tree.
51
51
  * @param [options] - The `options` parameter is an optional object that can contain additional
52
52
  * configuration options for the binary search tree. It can have the following properties:
53
53
  */
54
- constructor(elements?: Iterable<BTNExemplar<K, V, N>>, options?: Partial<BSTOptions<K>>);
54
+ constructor(nodes?: Iterable<KeyOrNodeOrEntry<K, V, N>>, options?: Partial<BSTOptions<K>>);
55
55
  protected _root?: N;
56
56
  get root(): N | undefined;
57
57
  protected _variant: BSTVariant;
@@ -74,27 +74,53 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
74
74
  */
75
75
  createTree(options?: Partial<BSTOptions<K>>): TREE;
76
76
  /**
77
- * The function checks if an exemplar is an instance of BSTNode.
78
- * @param exemplar - The `exemplar` parameter is a variable of type `BTNExemplar<K, V, N>`.
79
- * @returns a boolean value indicating whether the exemplar is an instance of the BSTNode class.
80
- */
81
- isNode(exemplar: BTNExemplar<K, V, N>): exemplar is N;
82
- /**
83
- * The function `exemplarToNode` takes an exemplar and returns a node if the exemplar is valid,
77
+ * The function `exemplarToNode` takes an keyOrNodeOrEntry and returns a node if the keyOrNodeOrEntry is valid,
84
78
  * otherwise it returns undefined.
85
- * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`, where:
79
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`, where:
86
80
  * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
87
- * `exemplarToNode` function. It represents the value associated with the exemplar node.
81
+ * `exemplarToNode` function. It represents the value associated with the keyOrNodeOrEntry node.
88
82
  * @returns a node of type N or undefined.
89
83
  */
90
- exemplarToNode(exemplar: BTNExemplar<K, V, N>, value?: V): N | undefined;
84
+ exemplarToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): N | undefined;
85
+ /**
86
+ * Time Complexity: O(log n)
87
+ * Space Complexity: O(log n)
88
+ * Average case for a balanced tree. Space for the recursive call stack in the worst case.
89
+ */
90
+ /**
91
+ * Time Complexity: O(log n)
92
+ * Space Complexity: O(log n)
93
+ *
94
+ * The function `ensureNode` returns the node corresponding to the given key if it is a node key,
95
+ * otherwise it returns the key itself.
96
+ * @param {K | N | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `N`, or
97
+ * `undefined`.
98
+ * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
99
+ * type of iteration to be performed. It has a default value of `IterationType.ITERATIVE`.
100
+ * @returns either a node object (N) or undefined.
101
+ */
102
+ ensureNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N | undefined;
103
+ /**
104
+ * The function "isNotNodeInstance" checks if a potential key is a K.
105
+ * @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
106
+ * data type.
107
+ * @returns a boolean value indicating whether the potentialKey is of type number or not.
108
+ */
109
+ isNotNodeInstance(potentialKey: KeyOrNodeOrEntry<K, V, N>): potentialKey is K;
110
+ /**
111
+ * The function checks if an keyOrNodeOrEntry is an instance of BSTNode.
112
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V, N>`.
113
+ * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the BSTNode class.
114
+ */
115
+ isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>): keyOrNodeOrEntry is N;
91
116
  /**
92
- * Time Complexity: O(log n) - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
93
- * Space Complexity: O(1) - Constant space is used.
117
+ * Time Complexity: O(log n)
118
+ * Space Complexity: O(1)
119
+ * - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
94
120
  */
95
121
  /**
96
- * Time Complexity: O(log n) - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
97
- * Space Complexity: O(1) - Constant space is used.
122
+ * Time Complexity: O(log n)
123
+ * Space Complexity: O(1)
98
124
  *
99
125
  * The `add` function adds a new node to a binary tree, updating the value if the key already exists
100
126
  * or inserting a new node if the key is unique.
@@ -104,14 +130,15 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
104
130
  * @returns The method `add` returns either the newly added node (`newNode`) or `undefined` if the
105
131
  * node was not added.
106
132
  */
107
- add(keyOrNodeOrEntry: BTNExemplar<K, V, N>, value?: V): N | undefined;
133
+ add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): boolean;
108
134
  /**
109
- * Time Complexity: O(k log n) - Adding each element individually in a balanced tree.
110
- * Space Complexity: O(k) - Additional space is required for the sorted array.
135
+ * Time Complexity: O(k log n)
136
+ * Space Complexity: O(k)
137
+ * Adding each element individually in a balanced tree. Additional space is required for the sorted array.
111
138
  */
112
139
  /**
113
- * Time Complexity: O(k log n) - Adding each element individually in a balanced tree.
114
- * Space Complexity: O(k) - Additional space is required for the sorted array.
140
+ * Time Complexity: O(k log n)
141
+ * Space Complexity: O(k)
115
142
  *
116
143
  * The `addMany` function in TypeScript adds multiple keys or nodes to a binary tree, optionally
117
144
  * balancing the tree after each addition.
@@ -122,41 +149,40 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
122
149
  * order. If not provided, undefined will be assigned as the value for each key or node.
123
150
  * @param [isBalanceAdd=true] - A boolean flag indicating whether the add operation should be
124
151
  * balanced or not. If set to true, the add operation will be balanced using a binary search tree
125
- * algorithm. If set to false, the add operation will not be balanced and the elements will be added
152
+ * algorithm. If set to false, the add operation will not be balanced and the nodes will be added
126
153
  * in the order they appear in the input.
127
154
  * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
128
155
  * type of iteration to use when adding multiple keys or nodes. It has a default value of
129
156
  * `this.iterationType`, which suggests that it is a property of the current object.
130
157
  * @returns The function `addMany` returns an array of nodes (`N`) or `undefined` values.
131
158
  */
132
- addMany(keysOrNodesOrEntries: Iterable<BTNExemplar<K, V, N>>, values?: Iterable<V | undefined>, isBalanceAdd?: boolean, iterationType?: IterationType): (N | undefined)[];
159
+ addMany(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, N>>, values?: Iterable<V | undefined>, isBalanceAdd?: boolean, iterationType?: IterationType): boolean[];
133
160
  /**
134
- * Time Complexity: O(n log n) - Adding each element individually in a balanced tree.
135
- * Space Complexity: O(n) - Additional space is required for the sorted array.
161
+ * Time Complexity: O(n log n)
162
+ * Space Complexity: O(n)
163
+ * Adding each element individually in a balanced tree. Additional space is required for the sorted array.
136
164
  */
137
165
  /**
138
- * Time Complexity: O(log n) - Average case for a balanced tree.
139
- * Space Complexity: O(1) - Constant space is used.
166
+ * Time Complexity: O(n log n)
167
+ * Space Complexity: O(n)
140
168
  *
141
169
  * The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
142
170
  * leftmost node if the comparison result is greater than.
143
171
  * @param {K | N | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
144
172
  * type `K`, `N`, or `undefined`. It represents the starting point for finding the last key in
145
173
  * the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).
146
- * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
147
- * be performed. It can have one of the following values:
148
174
  * @returns the key of the rightmost node in the binary tree if the comparison result is less than,
149
175
  * the key of the leftmost node if the comparison result is greater than, and the key of the
150
176
  * rightmost node otherwise. If no node is found, it returns 0.
151
177
  */
152
- lastKey(beginRoot?: BSTNKeyOrNode<K, N>): K | undefined;
178
+ lastKey(beginRoot?: KeyOrNodeOrEntry<K, V, N>): K | undefined;
153
179
  /**
154
- * Time Complexity: O(log n) - Average case for a balanced tree.
155
- * Space Complexity: O(1) - Constant space is used.
180
+ * Time Complexity: O(log n)
181
+ * Space Complexity: O(1)
156
182
  */
157
183
  /**
158
- * Time Complexity: O(log n) - Average case for a balanced tree.
159
- * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
184
+ * Time Complexity: O(log n)
185
+ * Space Complexity: O(1)
160
186
  *
161
187
  * The function `getNodeByKey` searches for a node in a binary tree based on a given key, using
162
188
  * either recursive or iterative methods.
@@ -170,29 +196,14 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
170
196
  */
171
197
  getNodeByKey(key: K, iterationType?: IterationType): N | undefined;
172
198
  /**
173
- * The function "isNotNodeInstance" checks if a potential key is a K.
174
- * @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
175
- * data type.
176
- * @returns a boolean value indicating whether the potentialKey is of type number or not.
177
- */
178
- isNotNodeInstance(potentialKey: BTNKeyOrNode<K, N>): potentialKey is K;
179
- /**
180
- * Time Complexity: O(log n) - Average case for a balanced tree.
181
- * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
182
- */
183
- /**
184
- * The function `ensureNode` returns the node corresponding to the given key if it is a node key,
185
- * otherwise it returns the key itself.
186
- * @param {K | N | undefined} key - The `key` parameter can be of type `K`, `N`, or
187
- * `undefined`.
188
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
189
- * type of iteration to be performed. It has a default value of `IterationType.ITERATIVE`.
190
- * @returns either a node object (N) or undefined.
191
- */
192
- ensureNode(key: BSTNKeyOrNode<K, N>, iterationType?: IterationType): N | undefined;
193
- /**
194
- * Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
195
- * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
199
+ * Time Complexity: O(log n)
200
+ * Space Complexity: O(log n)
201
+ * 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.
202
+ * /
203
+
204
+ /**
205
+ * Time Complexity: O(log n)
206
+ * Space Complexity: O(log n)
196
207
  *
197
208
  * The function `getNodes` returns an array of nodes that match a given identifier, using either a
198
209
  * recursive or iterative approach.
@@ -213,14 +224,15 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
213
224
  * performed on the binary tree. It can have two possible values:
214
225
  * @returns The method returns an array of nodes (`N[]`).
215
226
  */
216
- getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C> | undefined, callback?: C, onlyOne?: boolean, beginRoot?: BSTNKeyOrNode<K, N>, iterationType?: IterationType): N[];
227
+ getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C> | undefined, callback?: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N[];
217
228
  /**
218
- * Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
219
- * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
229
+ * Time Complexity: O(log n)
230
+ * Space Complexity: O(log n)
231
+ * 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.
220
232
  */
221
233
  /**
222
- * Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
223
- * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
234
+ * Time Complexity: O(log n)
235
+ * Space Complexity: O(log n)
224
236
  *
225
237
  * The `lesserOrGreaterTraverse` function traverses a binary tree and returns an array of nodes that
226
238
  * are either lesser or greater than a target node, depending on the specified comparison type.
@@ -239,14 +251,14 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
239
251
  * @returns The function `lesserOrGreaterTraverse` returns an array of values of type
240
252
  * `ReturnType<C>`, which is the return type of the callback function passed as an argument.
241
253
  */
242
- lesserOrGreaterTraverse<C extends BTNCallback<N>>(callback?: C, lesserOrGreater?: CP, targetNode?: BSTNKeyOrNode<K, N>, iterationType?: IterationType): ReturnType<C>[];
254
+ lesserOrGreaterTraverse<C extends BTNCallback<N>>(callback?: C, lesserOrGreater?: CP, targetNode?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): ReturnType<C>[];
243
255
  /**
244
- * Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
245
- * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
256
+ * Time Complexity: O(log n)
257
+ * Space Complexity: O(log n)
246
258
  */
247
259
  /**
248
- * Time Complexity: O(n) - Building a balanced tree from a sorted array.
249
- * Space Complexity: O(n) - Additional space is required for the sorted array.
260
+ * Time Complexity: O(log n)
261
+ * Space Complexity: O(log n)
250
262
  *
251
263
  * The `perfectlyBalance` function balances a binary search tree by adding nodes in a way that
252
264
  * ensures the tree is perfectly balanced.
@@ -270,8 +282,8 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
270
282
  * Space Complexity: O(n) - Additional space is required for the sorted array.
271
283
  */
272
284
  /**
273
- * Time Complexity: O(n) - Visiting each node once.
274
- * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
285
+ * Time Complexity: O(n)
286
+ * Space Complexity: O(log n)
275
287
  *
276
288
  * The function checks if a binary tree is AVL balanced using either recursive or iterative approach.
277
289
  * @param iterationType - The `iterationType` parameter is used to determine the method of iteration
@@ -56,13 +56,13 @@ export class BSTNode extends BinaryTreeNode {
56
56
  export class BST extends BinaryTree {
57
57
  /**
58
58
  * This is the constructor function for a binary search tree class in TypeScript, which initializes
59
- * the tree with optional elements and options.
60
- * @param [elements] - An optional iterable of BTNExemplar objects that will be added to the
59
+ * the tree with optional nodes and options.
60
+ * @param [nodes] - An optional iterable of KeyOrNodeOrEntry objects that will be added to the
61
61
  * binary search tree.
62
62
  * @param [options] - The `options` parameter is an optional object that can contain additional
63
63
  * configuration options for the binary search tree. It can have the following properties:
64
64
  */
65
- constructor(elements, options) {
65
+ constructor(nodes, options) {
66
66
  super([], options);
67
67
  if (options) {
68
68
  const { variant } = options;
@@ -71,14 +71,14 @@ export class BST extends BinaryTree {
71
71
  }
72
72
  }
73
73
  this._root = undefined;
74
- if (elements)
75
- this.addMany(elements);
74
+ if (nodes)
75
+ this.addMany(nodes);
76
76
  }
77
77
  _root;
78
78
  get root() {
79
79
  return this._root;
80
80
  }
81
- _variant = BSTVariant.MIN;
81
+ _variant = BSTVariant.STANDARD;
82
82
  get variant() {
83
83
  return this._variant;
84
84
  }
@@ -103,35 +103,28 @@ export class BST extends BinaryTree {
103
103
  createTree(options) {
104
104
  return new BST([], {
105
105
  iterationType: this.iterationType,
106
- variant: this.variant, ...options
106
+ variant: this.variant,
107
+ ...options
107
108
  });
108
109
  }
109
110
  /**
110
- * The function checks if an exemplar is an instance of BSTNode.
111
- * @param exemplar - The `exemplar` parameter is a variable of type `BTNExemplar<K, V, N>`.
112
- * @returns a boolean value indicating whether the exemplar is an instance of the BSTNode class.
113
- */
114
- isNode(exemplar) {
115
- return exemplar instanceof BSTNode;
116
- }
117
- /**
118
- * The function `exemplarToNode` takes an exemplar and returns a node if the exemplar is valid,
111
+ * The function `exemplarToNode` takes an keyOrNodeOrEntry and returns a node if the keyOrNodeOrEntry is valid,
119
112
  * otherwise it returns undefined.
120
- * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`, where:
113
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`, where:
121
114
  * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
122
- * `exemplarToNode` function. It represents the value associated with the exemplar node.
115
+ * `exemplarToNode` function. It represents the value associated with the keyOrNodeOrEntry node.
123
116
  * @returns a node of type N or undefined.
124
117
  */
125
- exemplarToNode(exemplar, value) {
118
+ exemplarToNode(keyOrNodeOrEntry, value) {
126
119
  let node;
127
- if (exemplar === null || exemplar === undefined) {
120
+ if (keyOrNodeOrEntry === null || keyOrNodeOrEntry === undefined) {
128
121
  return;
129
122
  }
130
- else if (this.isNode(exemplar)) {
131
- node = exemplar;
123
+ else if (this.isNode(keyOrNodeOrEntry)) {
124
+ node = keyOrNodeOrEntry;
132
125
  }
133
- else if (this.isEntry(exemplar)) {
134
- const [key, value] = exemplar;
126
+ else if (this.isEntry(keyOrNodeOrEntry)) {
127
+ const [key, value] = keyOrNodeOrEntry;
135
128
  if (key === undefined || key === null) {
136
129
  return;
137
130
  }
@@ -139,8 +132,8 @@ export class BST extends BinaryTree {
139
132
  node = this.createNode(key, value);
140
133
  }
141
134
  }
142
- else if (this.isNotNodeInstance(exemplar)) {
143
- node = this.createNode(exemplar, value);
135
+ else if (this.isNotNodeInstance(keyOrNodeOrEntry)) {
136
+ node = this.createNode(keyOrNodeOrEntry, value);
144
137
  }
145
138
  else {
146
139
  return;
@@ -148,12 +141,62 @@ export class BST extends BinaryTree {
148
141
  return node;
149
142
  }
150
143
  /**
151
- * Time Complexity: O(log n) - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
152
- * Space Complexity: O(1) - Constant space is used.
144
+ * Time Complexity: O(log n)
145
+ * Space Complexity: O(log n)
146
+ * Average case for a balanced tree. Space for the recursive call stack in the worst case.
153
147
  */
154
148
  /**
155
- * Time Complexity: O(log n) - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
156
- * Space Complexity: O(1) - Constant space is used.
149
+ * Time Complexity: O(log n)
150
+ * Space Complexity: O(log n)
151
+ *
152
+ * The function `ensureNode` returns the node corresponding to the given key if it is a node key,
153
+ * otherwise it returns the key itself.
154
+ * @param {K | N | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `N`, or
155
+ * `undefined`.
156
+ * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
157
+ * type of iteration to be performed. It has a default value of `IterationType.ITERATIVE`.
158
+ * @returns either a node object (N) or undefined.
159
+ */
160
+ ensureNode(keyOrNodeOrEntry, iterationType = IterationType.ITERATIVE) {
161
+ let res;
162
+ if (this.isRealNode(keyOrNodeOrEntry)) {
163
+ res = keyOrNodeOrEntry;
164
+ }
165
+ else if (this.isEntry(keyOrNodeOrEntry)) {
166
+ if (keyOrNodeOrEntry[0])
167
+ res = this.getNodeByKey(keyOrNodeOrEntry[0], iterationType);
168
+ }
169
+ else {
170
+ if (keyOrNodeOrEntry)
171
+ res = this.getNodeByKey(keyOrNodeOrEntry, iterationType);
172
+ }
173
+ return res;
174
+ }
175
+ /**
176
+ * The function "isNotNodeInstance" checks if a potential key is a K.
177
+ * @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
178
+ * data type.
179
+ * @returns a boolean value indicating whether the potentialKey is of type number or not.
180
+ */
181
+ isNotNodeInstance(potentialKey) {
182
+ return !(potentialKey instanceof BSTNode);
183
+ }
184
+ /**
185
+ * The function checks if an keyOrNodeOrEntry is an instance of BSTNode.
186
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V, N>`.
187
+ * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the BSTNode class.
188
+ */
189
+ isNode(keyOrNodeOrEntry) {
190
+ return keyOrNodeOrEntry instanceof BSTNode;
191
+ }
192
+ /**
193
+ * Time Complexity: O(log n)
194
+ * Space Complexity: O(1)
195
+ * - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
196
+ */
197
+ /**
198
+ * Time Complexity: O(log n)
199
+ * Space Complexity: O(1)
157
200
  *
158
201
  * The `add` function adds a new node to a binary tree, updating the value if the key already exists
159
202
  * or inserting a new node if the key is unique.
@@ -166,11 +209,11 @@ export class BST extends BinaryTree {
166
209
  add(keyOrNodeOrEntry, value) {
167
210
  const newNode = this.exemplarToNode(keyOrNodeOrEntry, value);
168
211
  if (newNode === undefined)
169
- return;
212
+ return false;
170
213
  if (this.root === undefined) {
171
214
  this._setRoot(newNode);
172
215
  this._size++;
173
- return this.root;
216
+ return true;
174
217
  }
175
218
  let current = this.root;
176
219
  while (current !== undefined) {
@@ -178,7 +221,7 @@ export class BST extends BinaryTree {
178
221
  // if (current !== newNode) {
179
222
  // The key value is the same but the reference is different, update the value of the existing node
180
223
  this._replaceNode(current, newNode);
181
- return newNode;
224
+ return true;
182
225
  // } else {
183
226
  // The key value is the same and the reference is the same, replace the entire node
184
227
  // this._replaceNode(current, newNode);
@@ -190,7 +233,7 @@ export class BST extends BinaryTree {
190
233
  current.left = newNode;
191
234
  newNode.parent = current;
192
235
  this._size++;
193
- return newNode;
236
+ return true;
194
237
  }
195
238
  current = current.left;
196
239
  }
@@ -199,20 +242,21 @@ export class BST extends BinaryTree {
199
242
  current.right = newNode;
200
243
  newNode.parent = current;
201
244
  this._size++;
202
- return newNode;
245
+ return true;
203
246
  }
204
247
  current = current.right;
205
248
  }
206
249
  }
207
- return undefined;
250
+ return false;
208
251
  }
209
252
  /**
210
- * Time Complexity: O(k log n) - Adding each element individually in a balanced tree.
211
- * Space Complexity: O(k) - Additional space is required for the sorted array.
253
+ * Time Complexity: O(k log n)
254
+ * Space Complexity: O(k)
255
+ * Adding each element individually in a balanced tree. Additional space is required for the sorted array.
212
256
  */
213
257
  /**
214
- * Time Complexity: O(k log n) - Adding each element individually in a balanced tree.
215
- * Space Complexity: O(k) - Additional space is required for the sorted array.
258
+ * Time Complexity: O(k log n)
259
+ * Space Complexity: O(k)
216
260
  *
217
261
  * The `addMany` function in TypeScript adds multiple keys or nodes to a binary tree, optionally
218
262
  * balancing the tree after each addition.
@@ -223,7 +267,7 @@ export class BST extends BinaryTree {
223
267
  * order. If not provided, undefined will be assigned as the value for each key or node.
224
268
  * @param [isBalanceAdd=true] - A boolean flag indicating whether the add operation should be
225
269
  * balanced or not. If set to true, the add operation will be balanced using a binary search tree
226
- * algorithm. If set to false, the add operation will not be balanced and the elements will be added
270
+ * algorithm. If set to false, the add operation will not be balanced and the nodes will be added
227
271
  * in the order they appear in the input.
228
272
  * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
229
273
  * type of iteration to use when adding multiple keys or nodes. It has a default value of
@@ -305,20 +349,19 @@ export class BST extends BinaryTree {
305
349
  return inserted;
306
350
  }
307
351
  /**
308
- * Time Complexity: O(n log n) - Adding each element individually in a balanced tree.
309
- * Space Complexity: O(n) - Additional space is required for the sorted array.
352
+ * Time Complexity: O(n log n)
353
+ * Space Complexity: O(n)
354
+ * Adding each element individually in a balanced tree. Additional space is required for the sorted array.
310
355
  */
311
356
  /**
312
- * Time Complexity: O(log n) - Average case for a balanced tree.
313
- * Space Complexity: O(1) - Constant space is used.
357
+ * Time Complexity: O(n log n)
358
+ * Space Complexity: O(n)
314
359
  *
315
360
  * The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
316
361
  * leftmost node if the comparison result is greater than.
317
362
  * @param {K | N | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
318
363
  * type `K`, `N`, or `undefined`. It represents the starting point for finding the last key in
319
364
  * the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).
320
- * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
321
- * be performed. It can have one of the following values:
322
365
  * @returns the key of the rightmost node in the binary tree if the comparison result is less than,
323
366
  * the key of the leftmost node if the comparison result is greater than, and the key of the
324
367
  * rightmost node otherwise. If no node is found, it returns 0.
@@ -327,7 +370,7 @@ export class BST extends BinaryTree {
327
370
  let current = this.ensureNode(beginRoot);
328
371
  if (!current)
329
372
  return undefined;
330
- if (this._variant === BSTVariant.MIN) {
373
+ if (this._variant === BSTVariant.STANDARD) {
331
374
  // For BSTVariant.MIN, find the rightmost node
332
375
  while (current.right !== undefined) {
333
376
  current = current.right;
@@ -342,12 +385,12 @@ export class BST extends BinaryTree {
342
385
  return current.key;
343
386
  }
344
387
  /**
345
- * Time Complexity: O(log n) - Average case for a balanced tree.
346
- * Space Complexity: O(1) - Constant space is used.
388
+ * Time Complexity: O(log n)
389
+ * Space Complexity: O(1)
347
390
  */
348
391
  /**
349
- * Time Complexity: O(log n) - Average case for a balanced tree.
350
- * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
392
+ * Time Complexity: O(log n)
393
+ * Space Complexity: O(1)
351
394
  *
352
395
  * The function `getNodeByKey` searches for a node in a binary tree based on a given key, using
353
396
  * either recursive or iterative methods.
@@ -391,33 +434,14 @@ export class BST extends BinaryTree {
391
434
  }
392
435
  }
393
436
  /**
394
- * The function "isNotNodeInstance" checks if a potential key is a K.
395
- * @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
396
- * data type.
397
- * @returns a boolean value indicating whether the potentialKey is of type number or not.
398
- */
399
- isNotNodeInstance(potentialKey) {
400
- return !(potentialKey instanceof BSTNode);
401
- }
402
- /**
403
- * Time Complexity: O(log n) - Average case for a balanced tree.
404
- * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
405
- */
406
- /**
407
- * The function `ensureNode` returns the node corresponding to the given key if it is a node key,
408
- * otherwise it returns the key itself.
409
- * @param {K | N | undefined} key - The `key` parameter can be of type `K`, `N`, or
410
- * `undefined`.
411
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
412
- * type of iteration to be performed. It has a default value of `IterationType.ITERATIVE`.
413
- * @returns either a node object (N) or undefined.
414
- */
415
- ensureNode(key, iterationType = IterationType.ITERATIVE) {
416
- return this.isNotNodeInstance(key) ? this.getNodeByKey(key, iterationType) : key;
417
- }
418
- /**
419
- * Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
420
- * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
437
+ * Time Complexity: O(log n)
438
+ * Space Complexity: O(log n)
439
+ * 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.
440
+ * /
441
+
442
+ /**
443
+ * Time Complexity: O(log n)
444
+ * Space Complexity: O(log n)
421
445
  *
422
446
  * The function `getNodes` returns an array of nodes that match a given identifier, using either a
423
447
  * recursive or iterative approach.
@@ -495,12 +519,13 @@ export class BST extends BinaryTree {
495
519
  return ans;
496
520
  }
497
521
  /**
498
- * Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
499
- * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
522
+ * Time Complexity: O(log n)
523
+ * Space Complexity: O(log n)
524
+ * 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.
500
525
  */
501
526
  /**
502
- * Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
503
- * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
527
+ * Time Complexity: O(log n)
528
+ * Space Complexity: O(log n)
504
529
  *
505
530
  * The `lesserOrGreaterTraverse` function traverses a binary tree and returns an array of nodes that
506
531
  * are either lesser or greater than a target node, depending on the specified comparison type.
@@ -560,12 +585,12 @@ export class BST extends BinaryTree {
560
585
  }
561
586
  }
562
587
  /**
563
- * Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
564
- * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
588
+ * Time Complexity: O(log n)
589
+ * Space Complexity: O(log n)
565
590
  */
566
591
  /**
567
- * Time Complexity: O(n) - Building a balanced tree from a sorted array.
568
- * Space Complexity: O(n) - Additional space is required for the sorted array.
592
+ * Time Complexity: O(log n)
593
+ * Space Complexity: O(log n)
569
594
  *
570
595
  * The `perfectlyBalance` function balances a binary search tree by adding nodes in a way that
571
596
  * ensures the tree is perfectly balanced.
@@ -624,8 +649,8 @@ export class BST extends BinaryTree {
624
649
  * Space Complexity: O(n) - Additional space is required for the sorted array.
625
650
  */
626
651
  /**
627
- * Time Complexity: O(n) - Visiting each node once.
628
- * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
652
+ * Time Complexity: O(n)
653
+ * Space Complexity: O(log n)
629
654
  *
630
655
  * The function checks if a binary tree is AVL balanced using either recursive or iterative approach.
631
656
  * @param iterationType - The `iterationType` parameter is used to determine the method of iteration
@@ -694,7 +719,7 @@ export class BST extends BinaryTree {
694
719
  _compare(a, b) {
695
720
  const extractedA = this.extractor(a);
696
721
  const extractedB = this.extractor(b);
697
- const compared = this.variant === BSTVariant.MIN ? extractedA - extractedB : extractedB - extractedA;
722
+ const compared = this.variant === BSTVariant.STANDARD ? extractedA - extractedB : extractedB - extractedA;
698
723
  return compared > 0 ? CP.gt : compared < 0 ? CP.lt : CP.eq;
699
724
  }
700
725
  }