bst-typed 2.0.5 → 2.1.0

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 (101) hide show
  1. package/dist/data-structures/base/iterable-element-base.d.ts +186 -83
  2. package/dist/data-structures/base/iterable-element-base.js +149 -107
  3. package/dist/data-structures/base/iterable-entry-base.d.ts +95 -119
  4. package/dist/data-structures/base/iterable-entry-base.js +59 -116
  5. package/dist/data-structures/base/linear-base.d.ts +250 -192
  6. package/dist/data-structures/base/linear-base.js +137 -274
  7. package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
  8. package/dist/data-structures/binary-tree/avl-tree-counter.js +171 -205
  9. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
  10. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +135 -87
  11. package/dist/data-structures/binary-tree/avl-tree.d.ts +138 -149
  12. package/dist/data-structures/binary-tree/avl-tree.js +208 -195
  13. package/dist/data-structures/binary-tree/binary-tree.d.ts +476 -632
  14. package/dist/data-structures/binary-tree/binary-tree.js +598 -869
  15. package/dist/data-structures/binary-tree/bst.d.ts +258 -306
  16. package/dist/data-structures/binary-tree/bst.js +505 -481
  17. package/dist/data-structures/binary-tree/red-black-tree.d.ts +107 -179
  18. package/dist/data-structures/binary-tree/red-black-tree.js +114 -209
  19. package/dist/data-structures/binary-tree/tree-counter.d.ts +132 -154
  20. package/dist/data-structures/binary-tree/tree-counter.js +172 -203
  21. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  22. package/dist/data-structures/binary-tree/tree-multi-map.js +105 -85
  23. package/dist/data-structures/graph/abstract-graph.d.ts +238 -233
  24. package/dist/data-structures/graph/abstract-graph.js +267 -237
  25. package/dist/data-structures/graph/directed-graph.d.ts +108 -224
  26. package/dist/data-structures/graph/directed-graph.js +146 -233
  27. package/dist/data-structures/graph/map-graph.d.ts +49 -55
  28. package/dist/data-structures/graph/map-graph.js +56 -59
  29. package/dist/data-structures/graph/undirected-graph.d.ts +103 -146
  30. package/dist/data-structures/graph/undirected-graph.js +129 -149
  31. package/dist/data-structures/hash/hash-map.d.ts +164 -338
  32. package/dist/data-structures/hash/hash-map.js +270 -457
  33. package/dist/data-structures/heap/heap.d.ts +214 -289
  34. package/dist/data-structures/heap/heap.js +340 -349
  35. package/dist/data-structures/heap/max-heap.d.ts +11 -47
  36. package/dist/data-structures/heap/max-heap.js +11 -66
  37. package/dist/data-structures/heap/min-heap.d.ts +12 -47
  38. package/dist/data-structures/heap/min-heap.js +11 -66
  39. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
  40. package/dist/data-structures/linked-list/doubly-linked-list.js +368 -494
  41. package/dist/data-structures/linked-list/singly-linked-list.d.ts +261 -310
  42. package/dist/data-structures/linked-list/singly-linked-list.js +447 -466
  43. package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -107
  44. package/dist/data-structures/linked-list/skip-linked-list.js +0 -100
  45. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
  46. package/dist/data-structures/priority-queue/max-priority-queue.js +11 -78
  47. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
  48. package/dist/data-structures/priority-queue/min-priority-queue.js +10 -79
  49. package/dist/data-structures/priority-queue/priority-queue.d.ts +2 -61
  50. package/dist/data-structures/priority-queue/priority-queue.js +8 -83
  51. package/dist/data-structures/queue/deque.d.ts +227 -254
  52. package/dist/data-structures/queue/deque.js +309 -348
  53. package/dist/data-structures/queue/queue.d.ts +180 -201
  54. package/dist/data-structures/queue/queue.js +265 -248
  55. package/dist/data-structures/stack/stack.d.ts +124 -102
  56. package/dist/data-structures/stack/stack.js +181 -125
  57. package/dist/data-structures/trie/trie.d.ts +164 -165
  58. package/dist/data-structures/trie/trie.js +189 -172
  59. package/dist/interfaces/binary-tree.d.ts +56 -6
  60. package/dist/interfaces/graph.d.ts +16 -0
  61. package/dist/types/data-structures/base/base.d.ts +1 -1
  62. package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -0
  63. package/dist/types/utils/utils.d.ts +1 -0
  64. package/dist/utils/utils.d.ts +1 -1
  65. package/dist/utils/utils.js +2 -1
  66. package/package.json +2 -2
  67. package/src/data-structures/base/iterable-element-base.ts +238 -115
  68. package/src/data-structures/base/iterable-entry-base.ts +96 -120
  69. package/src/data-structures/base/linear-base.ts +271 -277
  70. package/src/data-structures/binary-tree/avl-tree-counter.ts +198 -216
  71. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +192 -101
  72. package/src/data-structures/binary-tree/avl-tree.ts +239 -206
  73. package/src/data-structures/binary-tree/binary-tree.ts +664 -893
  74. package/src/data-structures/binary-tree/bst.ts +568 -570
  75. package/src/data-structures/binary-tree/red-black-tree.ts +161 -222
  76. package/src/data-structures/binary-tree/tree-counter.ts +199 -218
  77. package/src/data-structures/binary-tree/tree-multi-map.ts +131 -97
  78. package/src/data-structures/graph/abstract-graph.ts +339 -264
  79. package/src/data-structures/graph/directed-graph.ts +146 -236
  80. package/src/data-structures/graph/map-graph.ts +63 -60
  81. package/src/data-structures/graph/undirected-graph.ts +129 -152
  82. package/src/data-structures/hash/hash-map.ts +274 -496
  83. package/src/data-structures/heap/heap.ts +389 -402
  84. package/src/data-structures/heap/max-heap.ts +12 -76
  85. package/src/data-structures/heap/min-heap.ts +13 -76
  86. package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
  87. package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
  88. package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
  89. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
  90. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
  91. package/src/data-structures/priority-queue/priority-queue.ts +3 -92
  92. package/src/data-structures/queue/deque.ts +381 -357
  93. package/src/data-structures/queue/queue.ts +310 -264
  94. package/src/data-structures/stack/stack.ts +217 -131
  95. package/src/data-structures/trie/trie.ts +240 -175
  96. package/src/interfaces/binary-tree.ts +240 -6
  97. package/src/interfaces/graph.ts +37 -0
  98. package/src/types/data-structures/base/base.ts +5 -5
  99. package/src/types/data-structures/graph/abstract-graph.ts +5 -0
  100. package/src/types/utils/utils.ts +2 -0
  101. package/src/utils/utils.ts +9 -14
@@ -6,36 +6,72 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import { BST, BSTNode } from './bst';
9
- import type { AVLTreeOptions, BinaryTreeDeleteResult, BSTNOptKeyOrNode, EntryCallback } from '../../types';
9
+ import type { AVLTreeOptions, BinaryTreeDeleteResult, BinaryTreeOptions, BSTNOptKeyOrNode, EntryCallback, IterationType } from '../../types';
10
+ import { BSTOptions } from '../../types';
10
11
  import { IBinaryTree } from '../../interfaces';
12
+ /**
13
+ * Represents a Node in an AVL (Adelson-Velsky and Landis) Tree.
14
+ * It extends a BSTNode and ensures the 'height' property is maintained.
15
+ *
16
+ * @template K - The type of the key.
17
+ * @template V - The type of the value.
18
+ */
11
19
  export declare class AVLTreeNode<K = any, V = any> extends BSTNode<K, V> {
12
20
  parent?: AVLTreeNode<K, V>;
13
21
  /**
14
- * This TypeScript constructor function initializes an instance with a key and an optional value.
15
- * @param {K} key - The `key` parameter is typically used to uniquely identify an object or element
16
- * within a data structure. It serves as a reference or identifier for accessing or manipulating the
17
- * associated value or data.
18
- * @param {V} [value] - The `value` parameter in the constructor is optional, meaning it does not
19
- * have to be provided when creating an instance of the class. If a value is not provided, it will
20
- * default to `undefined`.
22
+ * Creates an instance of AVLTreeNode.
23
+ * @remarks Time O(1), Space O(1)
24
+ *
25
+ * @param key - The key of the node.
26
+ * @param [value] - The value associated with the key.
21
27
  */
22
28
  constructor(key: K, value?: V);
23
29
  _left?: AVLTreeNode<K, V> | null | undefined;
30
+ /**
31
+ * Gets the left child of the node.
32
+ * @remarks Time O(1), Space O(1)
33
+ *
34
+ * @returns The left child.
35
+ */
24
36
  get left(): AVLTreeNode<K, V> | null | undefined;
37
+ /**
38
+ * Sets the left child of the node and updates its parent reference.
39
+ * @remarks Time O(1), Space O(1)
40
+ *
41
+ * @param v - The node to set as the left child.
42
+ */
25
43
  set left(v: AVLTreeNode<K, V> | null | undefined);
26
44
  _right?: AVLTreeNode<K, V> | null | undefined;
45
+ /**
46
+ * Gets the right child of the node.
47
+ * @remarks Time O(1), Space O(1)
48
+ *
49
+ * @returns The right child.
50
+ */
27
51
  get right(): AVLTreeNode<K, V> | null | undefined;
52
+ /**
53
+ * Sets the right child of the node and updates its parent reference.
54
+ * @remarks Time O(1), Space O(1)
55
+ *
56
+ * @param v - The node to set as the right child.
57
+ */
28
58
  set right(v: AVLTreeNode<K, V> | null | undefined);
29
59
  }
30
60
  /**
61
+ * Represents a self-balancing AVL (Adelson-Velsky and Landis) Tree.
62
+ * This tree extends BST and performs rotations on add/delete to maintain balance.
63
+ *
64
+ * @template K - The type of the key.
65
+ * @template V - The type of the value.
66
+ * @template R - The type of the raw data object (if using `toEntryFn`).
67
+ *
31
68
  * 1. Height-Balanced: Each node's left and right subtrees differ in height by no more than one.
32
69
  * 2. Automatic Rebalancing: AVL trees rebalance themselves automatically during insertions and deletions.
33
70
  * 3. Rotations for Balancing: Utilizes rotations (single or double) to maintain balance after updates.
34
71
  * 4. Order Preservation: Maintains the binary search tree property where left child values are less than the parent, and right child values are greater.
35
72
  * 5. Efficient Lookups: Offers O(log n) search time, where 'n' is the number of nodes, due to its balanced nature.
36
73
  * 6. Complex Insertions and Deletions: Due to rebalancing, these operations are more complex than in a regular BST.
37
- * 7. Path Length: The path length from the root to any leaf is longer compared to an unbalanced BST, but shorter than a linear chain of nodes.
38
- * @example
74
+ * 7. Path Length: The path length from the root to any leaf is longer compared to an unbalanced BST, but shorter than a linear chain of nodes.@example
39
75
  * // Find elements in a range
40
76
  * // In interval queries, AVL trees, with their strictly balanced structure and lower height, offer better query efficiency, making them ideal for frequent and high-performance interval queries. In contrast, Red-Black trees, with lower update costs, are more suitable for scenarios involving frequent insertions and deletions where the requirements for interval queries are less demanding.
41
77
  * type Datum = { timestamp: Date; temperature: number };
@@ -100,203 +136,156 @@ export declare class AVLTreeNode<K = any, V = any> extends BSTNode<K, V> {
100
136
  * // { minute: 15, temperature: 58.6 }
101
137
  * // ]
102
138
  */
103
- export declare class AVLTree<K = any, V = any, R = object, MK = any, MV = any, MR = object> extends BST<K, V, R, MK, MV, MR> implements IBinaryTree<K, V, R, MK, MV, MR> {
104
- /**
105
- * This TypeScript constructor initializes an AVLTree with keys, nodes, entries, or raw data provided
106
- * in an iterable format.
107
- * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
108
- * iterable that can contain either `
109
- K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` objects or `R` objects. It is
110
- * used to initialize the AVLTree with key-value pairs or raw data entries. If provided
111
- * @param [options] - The `options` parameter in the constructor is of type `AVLTreeOptions<K, V,
112
- * R>`. It is an optional parameter that allows you to specify additional options for configuring the
113
- * AVL tree. These options could include things like custom comparators, initial capacity, or any
114
- * other configuration settings specific
115
- */
116
- constructor(keysNodesEntriesOrRaws?: Iterable<K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, options?: AVLTreeOptions<K, V, R>);
139
+ export declare class AVLTree<K = any, V = any, R extends object = object> extends BST<K, V, R> implements IBinaryTree<K, V, R> {
117
140
  /**
118
- * Time Complexity: O(1)
119
- * Space Complexity: O(1)
141
+ * Creates an instance of AVLTree.
142
+ * @remarks Time O(N log N) (from `addMany` with balanced add). Space O(N).
120
143
  *
121
- * The function creates a new AVL tree node with the given key and value.
122
- * @param {K} key - The key parameter is of type K, which represents the key of the node being
123
- * created.
124
- * @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
125
- * value associated with the key in the node being created.
126
- * @returns The method is returning a new instance of the AVLTreeNode class, casted as the generic
127
- * type AVLTreeNode<K, V>.
144
+ * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to add.
145
+ * @param [options] - Configuration options for the AVL tree.
128
146
  */
129
- createNode(key: K, value?: V): AVLTreeNode<K, V>;
147
+ constructor(keysNodesEntriesOrRaws?: Iterable<K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, options?: AVLTreeOptions<K, V, R>);
130
148
  /**
131
- * Time Complexity: O(1)
132
- * Space Complexity: O(1)
149
+ * (Protected) Creates a new AVL tree node.
150
+ * @remarks Time O(1), Space O(1)
133
151
  *
134
- * The function creates a new AVL tree with the specified options and returns it.
135
- * @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be
136
- * passed to the `createTree` function. It is used to customize the behavior of the AVL tree that is
137
- * being created.
138
- * @returns a new AVLTree object.
152
+ * @param key - The key for the new node.
153
+ * @param [value] - The value for the new node.
154
+ * @returns The newly created AVLTreeNode.
139
155
  */
140
- createTree(options?: AVLTreeOptions<K, V, R>): AVLTree<K, V, R, MK, MV, MR>;
156
+ _createNode(key: K, value?: V): AVLTreeNode<K, V>;
141
157
  /**
142
- * Time Complexity: O(1)
143
- * Space Complexity: O(1)
158
+ * Checks if the given item is an `AVLTreeNode` instance.
159
+ * @remarks Time O(1), Space O(1)
144
160
  *
145
- * The function checks if the input is an instance of AVLTreeNode.
146
- * @param {K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
147
- * `keyNodeOrEntry` can be of type `R` or `
148
- K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `.
149
- * @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
150
- * an instance of the `AVLTreeNode` class.
161
+ * @param keyNodeOrEntry - The item to check.
162
+ * @returns True if it's an AVLTreeNode, false otherwise.
151
163
  */
152
164
  isNode(keyNodeOrEntry: K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): keyNodeOrEntry is AVLTreeNode<K, V>;
153
165
  /**
154
- * Time Complexity: O(log n)
155
- * Space Complexity: O(log n)
166
+ * Adds a new node to the AVL tree and balances the tree path.
167
+ * @remarks Time O(log N) (O(H) for BST add + O(H) for `_balancePath`). Space O(H) for path/recursion.
156
168
  *
157
- * The function overrides the add method of a class and inserts a key-value pair into a data
158
- * structure, then balances the path.
159
- * @param { K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
160
- * `keyNodeOrEntry` can accept values of type `R`, `
161
- K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `
162
- * @param {V} [value] - The `value` parameter is an optional value that you want to associate with
163
- * the key or node being added to the data structure.
164
- * @returns The method is returning a boolean value.
169
+ * @param keyNodeOrEntry - The key, node, or entry to add.
170
+ * @param [value] - The value, if providing just a key.
171
+ * @returns True if the addition was successful, false otherwise.
165
172
  */
166
173
  add(keyNodeOrEntry: K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V): boolean;
167
174
  /**
168
- * Time Complexity: O(log n)
169
- * Space Complexity: O(log n)
175
+ * Deletes a node from the AVL tree and re-balances the tree.
176
+ * @remarks Time O(log N) (O(H) for BST delete + O(H) for `_balancePath`). Space O(H) for path/recursion.
170
177
  *
171
- * The function overrides the delete method in a TypeScript class, performs deletion, and then
172
- * balances the tree if necessary.
173
- * @param { K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The `keyNodeOrEntry`
174
- * parameter in the `override delete` method can be one of the following types:
175
- * @returns The `delete` method is being overridden in this code snippet. It first calls the `delete`
176
- * method from the superclass (presumably a parent class) with the provided `predicate`, which could
177
- * be a key, node, entry, or a custom predicate. The result of this deletion operation is stored in
178
- * `deletedResults`, which is an array of `BinaryTreeDeleteResult` objects.
178
+ * @param keyNodeOrEntry - The node to delete.
179
+ * @returns An array containing deletion results.
179
180
  */
180
181
  delete(keyNodeOrEntry: K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): BinaryTreeDeleteResult<AVLTreeNode<K, V>>[];
181
182
  /**
182
- * Time Complexity: O(n)
183
- * Space Complexity: O(n)
183
+ * Rebuilds the tree to be perfectly balanced.
184
+ * @remarks AVL trees are already height-balanced, but this makes them *perfectly* balanced (minimal height and all leaves at N or N-1).
185
+ * Time O(N) (O(N) for DFS, O(N) for sorted build). Space O(N) for node array and recursion stack.
186
+ *
187
+ * @param [iterationType=this.iterationType] - The traversal method for the initial node export.
188
+ * @returns True if successful, false if the tree was empty.
189
+ */
190
+ perfectlyBalance(iterationType?: IterationType): boolean;
191
+ /**
192
+ * Creates a new AVLTree by mapping each [key, value] pair.
193
+ * @remarks Time O(N log N) (O(N) iteration + O(log M) `add` for each item into the new tree). Space O(N) for the new tree.
194
+ *
195
+ * @template MK - New key type.
196
+ * @template MV - New value type.
197
+ * @template MR - New raw type.
198
+ * @param callback - A function to map each [key, value] pair.
199
+ * @param [options] - Options for the new AVLTree.
200
+ * @param [thisArg] - `this` context for the callback.
201
+ * @returns A new, mapped AVLTree.
202
+ */
203
+ map<MK = K, MV = V, MR extends object = object>(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: Partial<BinaryTreeOptions<MK, MV, MR>>, thisArg?: unknown): AVLTree<MK, MV, MR>;
204
+ /**
205
+ * (Protected) Creates a new, empty instance of the same AVLTree constructor.
206
+ * @remarks Time O(1)
184
207
  *
185
- * The `map` function in TypeScript overrides the default map behavior of an AVLTree data structure
186
- * by applying a callback function to each entry and creating a new AVLTree with the results.
187
- * @param callback - A function that will be called for each entry in the AVLTree. It takes four
188
- * arguments: the key, the value (which can be undefined), the index of the entry, and a reference to
189
- * the AVLTree itself.
190
- * @param [options] - The `options` parameter in the `override map` function is of type
191
- * `AVLTreeOptions<MK, MV, MR>`. It is an optional parameter that allows you to specify additional
192
- * options for the AVL tree being created during the mapping process. These options could include
193
- * custom comparators, initial
194
- * @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
195
- * the value of `this` when executing the `callback` function. It allows you to set the context
196
- * (value of `this`) within the callback function. This can be useful when you want to access
197
- * properties or
198
- * @returns The `map` method is returning a new AVLTree instance (`newTree`) with the entries
199
- * modified by the provided callback function.
208
+ * @template TK, TV, TR - Generic types for the new instance.
209
+ * @param [options] - Options for the new tree.
210
+ * @returns A new, empty tree.
200
211
  */
201
- map(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: AVLTreeOptions<MK, MV, MR>, thisArg?: any): AVLTree<MK, MV, MR>;
212
+ protected _createInstance<TK = K, TV = V, TR extends object = R>(options?: Partial<BSTOptions<TK, TV, TR>>): this;
202
213
  /**
203
- * Time Complexity: O(n)
204
- * Space Complexity: O(n)
214
+ * (Protected) Creates a new instance of the same AVLTree constructor, potentially with different generic types.
215
+ * @remarks Time O(N log N) (from constructor) due to processing the iterable.
205
216
  *
206
- * The function `clone` overrides the default cloning behavior to create a deep copy of a tree
207
- * structure.
208
- * @returns A cloned tree object is being returned.
217
+ * @template TK, TV, TR - Generic types for the new instance.
218
+ * @param [iter=[]] - An iterable to populate the new tree.
219
+ * @param [options] - Options for the new tree.
220
+ * @returns A new AVLTree.
209
221
  */
210
- clone(): AVLTree<K, V, R, MK, MV, MR>;
222
+ protected _createLike<TK = K, TV = V, TR extends object = R>(iter?: Iterable<TK | BSTNode<TK, TV> | [TK | null | undefined, TV | undefined] | null | undefined | TR>, options?: Partial<BSTOptions<TK, TV, TR>>): AVLTree<TK, TV, TR>;
211
223
  /**
212
- * Time Complexity: O(1)
213
- * Space Complexity: O(1)
224
+ * (Protected) Swaps properties of two nodes, including height.
225
+ * @remarks Time O(H) (due to `ensureNode`), but O(1) if nodes are passed directly.
214
226
  *
215
- * The `_swapProperties` function swaps the key, value, and height properties between two nodes in a
216
- * binary search tree.
217
- * @param {BSTNOptKeyOrNode<K, AVLTreeNode<K, V>>} srcNode - The `srcNode` parameter represents either a node
218
- * object (`AVLTreeNode<K, V>`) or a key-value pair (`R`) that is being swapped with another node.
219
- * @param {BSTNOptKeyOrNode<K, AVLTreeNode<K, V>>} destNode - The `destNode` parameter is either an instance of
220
- * `R` or an instance of `BSTNOptKeyOrNode<K, AVLTreeNode<K, V>>`.
221
- * @returns The method is returning the `destNodeEnsured` object if both `srcNodeEnsured` and
222
- * `destNodeEnsured` are truthy. Otherwise, it returns `undefined`.
227
+ * @param srcNode - The source node.
228
+ * @param destNode - The destination node.
229
+ * @returns The `destNode` (now holding `srcNode`'s properties).
223
230
  */
224
231
  protected _swapProperties(srcNode: BSTNOptKeyOrNode<K, AVLTreeNode<K, V>>, destNode: BSTNOptKeyOrNode<K, AVLTreeNode<K, V>>): AVLTreeNode<K, V> | undefined;
225
232
  /**
226
- * Time Complexity: O(1)
227
- * Space Complexity: O(1)
233
+ * (Protected) Calculates the balance factor (height(right) - height(left)).
234
+ * @remarks Time O(1) (assumes heights are stored).
228
235
  *
229
- * The function calculates the balance factor of a node in a binary tree.
230
- * @param {AVLTreeNode<K, V>} node - The parameter "node" is of type "AVLTreeNode<K, V>", which likely represents a node in a
231
- * binary tree data structure.
232
- * @returns the balance factor of a given node. The balance factor is calculated by subtracting the
233
- * height of the left subtree from the height of the right subtree.
236
+ * @param node - The node to check.
237
+ * @returns The balance factor (positive if right-heavy, negative if left-heavy).
234
238
  */
235
239
  protected _balanceFactor(node: AVLTreeNode<K, V>): number;
236
240
  /**
237
- * Time Complexity: O(1)
238
- * Space Complexity: O(1)
241
+ * (Protected) Recalculates and updates the height of a node based on its children's heights.
242
+ * @remarks Time O(1) (assumes children's heights are correct).
239
243
  *
240
- * The function updates the height of a node in a binary tree based on the heights of its left and
241
- * right children.
242
- * @param {AVLTreeNode<K, V>} node - The parameter "node" represents a node in a binary tree data structure.
244
+ * @param node - The node to update.
243
245
  */
244
246
  protected _updateHeight(node: AVLTreeNode<K, V>): void;
245
247
  /**
246
- * Time Complexity: O(1)
247
- * Space Complexity: O(1)
248
+ * (Protected) Performs a Left-Left (LL) rotation (a single right rotation).
249
+ * @remarks Time O(1), Space O(1)
248
250
  *
249
- * The `_balanceLL` function performs a left-left rotation to balance a binary search tree.
250
- * @param {AVLTreeNode<K, V>} A - A is a node in a binary tree.
251
+ * @param A - The unbalanced node (root of the unbalanced subtree).
251
252
  */
252
253
  protected _balanceLL(A: AVLTreeNode<K, V>): void;
253
254
  /**
254
- * Time Complexity: O(1)
255
- * Space Complexity: O(1)
255
+ * (Protected) Performs a Left-Right (LR) double rotation.
256
+ * @remarks Time O(1), Space O(1)
256
257
  *
257
- * The `_balanceLR` function performs a left-right rotation to balance a binary tree.
258
- * @param {AVLTreeNode<K, V>} A - A is a node in a binary tree.
258
+ * @param A - The unbalanced node (root of the unbalanced subtree).
259
259
  */
260
260
  protected _balanceLR(A: AVLTreeNode<K, V>): void;
261
261
  /**
262
- * Time Complexity: O(1)
263
- * Space Complexity: O(1)
262
+ * (Protected) Performs a Right-Right (RR) rotation (a single left rotation).
263
+ * @remarks Time O(1), Space O(1)
264
264
  *
265
- * The function `_balanceRR` performs a right-right rotation to balance a binary tree.
266
- * @param {AVLTreeNode<K, V>} A - A is a node in a binary tree.
265
+ * @param A - The unbalanced node (root of the unbalanced subtree).
267
266
  */
268
267
  protected _balanceRR(A: AVLTreeNode<K, V>): void;
269
268
  /**
270
- * Time Complexity: O(1)
271
- * Space Complexity: O(1)
269
+ * (Protected) Performs a Right-Left (RL) double rotation.
270
+ * @remarks Time O(1), Space O(1)
272
271
  *
273
- * The function `_balanceRL` performs a right-left rotation to balance a binary tree.
274
- * @param {AVLTreeNode<K, V>} A - A is a node in a binary tree.
272
+ * @param A - The unbalanced node (root of the unbalanced subtree).
275
273
  */
276
274
  protected _balanceRL(A: AVLTreeNode<K, V>): void;
277
275
  /**
278
- * Time Complexity: O(log n)
279
- * Space Complexity: O(1)
276
+ * (Protected) Traverses up the tree from the specified node, updating heights and performing rotations as needed.
277
+ * @remarks Time O(log N) (O(H)), as it traverses the path to root. Space O(H) for the path array.
280
278
  *
281
- * The `_balancePath` function is used to update the heights of nodes and perform rotation operations
282
- * to restore balance in an AVL tree after inserting a node.
283
- * @param { K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } node - The `node` parameter can be of type `R` or
284
- * `
285
- K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `.
279
+ * @param node - The node to start balancing from (e.g., the newly inserted node or parent of the deleted node).
286
280
  */
287
281
  protected _balancePath(node: K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): void;
288
282
  /**
289
- * Time Complexity: O(1)
290
- * Space Complexity: O(1)
283
+ * (Protected) Replaces a node, ensuring height is copied.
284
+ * @remarks Time O(1)
291
285
  *
292
- * The function replaces an old node with a new node and sets the height of the new node to be the
293
- * same as the old node.
294
- * @param {AVLTreeNode<K, V>} oldNode - The `oldNode` parameter represents the node that needs to be replaced in
295
- * the data structure.
296
- * @param {AVLTreeNode<K, V>} newNode - The `newNode` parameter is the new node that will replace the `oldNode` in
297
- * the data structure.
298
- * @returns The method is returning the result of calling the `_replaceNode` method from the
299
- * superclass, with the `oldNode` and `newNode` as arguments.
286
+ * @param oldNode - The node to be replaced.
287
+ * @param newNode - The node to insert.
288
+ * @returns The `newNode`.
300
289
  */
301
290
  protected _replaceNode(oldNode: AVLTreeNode<K, V>, newNode: AVLTreeNode<K, V>): AVLTreeNode<K, V>;
302
291
  }