min-heap-typed 1.42.8 → 1.42.9

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 (49) hide show
  1. package/dist/data-structures/binary-tree/avl-tree.d.ts +88 -23
  2. package/dist/data-structures/binary-tree/avl-tree.js +88 -23
  3. package/dist/data-structures/binary-tree/binary-tree.d.ts +180 -74
  4. package/dist/data-structures/binary-tree/binary-tree.js +388 -201
  5. package/dist/data-structures/binary-tree/bst.d.ts +121 -66
  6. package/dist/data-structures/binary-tree/bst.js +121 -67
  7. package/dist/data-structures/binary-tree/rb-tree.d.ts +72 -5
  8. package/dist/data-structures/binary-tree/rb-tree.js +95 -18
  9. package/dist/data-structures/binary-tree/tree-multimap.d.ts +82 -43
  10. package/dist/data-structures/binary-tree/tree-multimap.js +82 -43
  11. package/dist/data-structures/graph/abstract-graph.d.ts +139 -36
  12. package/dist/data-structures/graph/abstract-graph.js +147 -36
  13. package/dist/data-structures/graph/directed-graph.d.ts +126 -0
  14. package/dist/data-structures/graph/directed-graph.js +126 -0
  15. package/dist/data-structures/graph/undirected-graph.d.ts +63 -0
  16. package/dist/data-structures/graph/undirected-graph.js +63 -0
  17. package/dist/data-structures/heap/heap.d.ts +175 -12
  18. package/dist/data-structures/heap/heap.js +175 -12
  19. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +203 -0
  20. package/dist/data-structures/linked-list/doubly-linked-list.js +203 -0
  21. package/dist/data-structures/linked-list/singly-linked-list.d.ts +182 -0
  22. package/dist/data-structures/linked-list/singly-linked-list.js +182 -0
  23. package/dist/data-structures/linked-list/skip-linked-list.d.ts +64 -0
  24. package/dist/data-structures/linked-list/skip-linked-list.js +64 -0
  25. package/dist/data-structures/queue/deque.d.ts +113 -3
  26. package/dist/data-structures/queue/deque.js +113 -3
  27. package/dist/data-structures/queue/queue.d.ts +87 -0
  28. package/dist/data-structures/queue/queue.js +87 -0
  29. package/dist/data-structures/stack/stack.d.ts +42 -0
  30. package/dist/data-structures/stack/stack.js +42 -0
  31. package/dist/data-structures/trie/trie.d.ts +76 -0
  32. package/dist/data-structures/trie/trie.js +76 -1
  33. package/package.json +2 -2
  34. package/src/data-structures/binary-tree/avl-tree.ts +97 -23
  35. package/src/data-structures/binary-tree/binary-tree.ts +419 -204
  36. package/src/data-structures/binary-tree/bst.ts +130 -68
  37. package/src/data-structures/binary-tree/rb-tree.ts +106 -19
  38. package/src/data-structures/binary-tree/tree-multimap.ts +88 -44
  39. package/src/data-structures/graph/abstract-graph.ts +133 -7
  40. package/src/data-structures/graph/directed-graph.ts +145 -1
  41. package/src/data-structures/graph/undirected-graph.ts +72 -0
  42. package/src/data-structures/heap/heap.ts +201 -12
  43. package/src/data-structures/linked-list/doubly-linked-list.ts +232 -0
  44. package/src/data-structures/linked-list/singly-linked-list.ts +208 -0
  45. package/src/data-structures/linked-list/skip-linked-list.ts +74 -0
  46. package/src/data-structures/queue/deque.ts +127 -3
  47. package/src/data-structures/queue/queue.ts +99 -0
  48. package/src/data-structures/stack/stack.ts +48 -0
  49. package/src/data-structures/trie/trie.ts +87 -4
@@ -66,11 +66,11 @@ export class BSTNode<V = any, N extends BSTNode<V, N> = BSTNodeNested<V>> extend
66
66
  export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>>
67
67
  extends BinaryTree<V, N>
68
68
  implements IBinaryTree<V, N> {
69
+
69
70
  /**
70
- * The constructor function initializes a binary search tree object with an optional comparator
71
- * function.
72
- * @param {BSTOptions} [options] - An optional object that contains configuration options for the
73
- * binary search tree.
71
+ * The constructor function initializes a binary search tree with an optional comparator function.
72
+ * @param {BSTOptions} [options] - An optional object that contains additional configuration options
73
+ * for the binary search tree.
74
74
  */
75
75
  constructor(options?: BSTOptions) {
76
76
  super(options);
@@ -105,14 +105,22 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
105
105
  }
106
106
 
107
107
  /**
108
- * The `add` function in a binary search tree class inserts a new node with a given key and value
109
- * into the tree.
110
- * @param {BTNKey | N | undefined} keyOrNode - The `keyOrNode` parameter can be either a
111
- * `BTNKey` (which can be a number or a string), a `BSTNode` object, or `undefined`.
112
- * @param [value] - The `value` parameter is the value to be assigned to the new node being added to the
113
- * binary search tree.
114
- * @returns the inserted node (N) if it was successfully added to the binary search tree. If the node
115
- * was not added or if the parameters were invalid, it returns undefined or undefined.
108
+ * Time Complexity: O(log n) - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
109
+ * Space Complexity: O(1) - Constant space is used.
110
+ */
111
+
112
+
113
+ /**
114
+ * Time Complexity: O(log n) - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
115
+ * Space Complexity: O(1) - Constant space is used.
116
+ *
117
+ * The `add` function adds a new node to a binary search tree based on the provided key and value.
118
+ * @param {BTNKey | N | null | undefined} keyOrNode - The `keyOrNode` parameter can be one of the
119
+ * following types:
120
+ * @param {V} [value] - The `value` parameter is an optional value that can be associated with the
121
+ * key or node being added to the binary search tree.
122
+ * @returns The method `add` returns a node (`N`) that was inserted into the binary search tree. If
123
+ * no node was inserted, it returns `undefined`.
116
124
  */
117
125
  override add(keyOrNode: BTNKey | N | null | undefined, value?: V): N | undefined {
118
126
  if (keyOrNode === null) return undefined;
@@ -182,17 +190,29 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
182
190
  }
183
191
 
184
192
  /**
185
- * The `addMany` function is used to efficiently add multiple nodes to a binary search tree while
186
- * maintaining balance.
187
- * @param {[BTNKey | N, V][]} keysOrNodes - The `arr` parameter in the `addMany` function
188
- * represents an array of keys or nodes that need to be added to the binary search tree. It can be an
189
- * array of `BTNKey` or `N` (which represents the node type in the binary search tree) or
190
- * `undefined
191
- * @param {V[]} data - The values of tree nodes
192
- * @param {boolean} isBalanceAdd - If true the nodes will be balance inserted in binary search method.
193
- * @param iterationType - The `iterationType` parameter determines the type of iteration to be used.
194
- * It can have two possible values:
195
- * @returns The `addMany` function returns an array of `N`, `undefined`, or `undefined` values.
193
+ * Time Complexity: O(n log n) - Adding each element individually in a balanced tree.
194
+ * Space Complexity: O(n) - Additional space is required for the sorted array.
195
+ */
196
+
197
+ /**
198
+ * Time Complexity: O(n log n) - Adding each element individually in a balanced tree.
199
+ * Space Complexity: O(n) - Additional space is required for the sorted array.
200
+ *
201
+ * The `addMany` function is used to efficiently add multiple keys or nodes with corresponding data
202
+ * to a binary search tree.
203
+ * @param {(BTNKey | N | undefined)[]} keysOrNodes - An array of keys or nodes to be added to the
204
+ * binary search tree. Each element can be of type `BTNKey` (binary tree node key), `N` (binary tree
205
+ * node), or `undefined`.
206
+ * @param {(V | undefined)[]} [data] - An optional array of values to associate with the keys or
207
+ * nodes being added. If provided, the length of the `data` array must be the same as the length of
208
+ * the `keysOrNodes` array.
209
+ * @param [isBalanceAdd=true] - A boolean flag indicating whether the tree should be balanced after
210
+ * adding the nodes. The default value is `true`.
211
+ * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
212
+ * type of iteration to use when adding multiple keys or nodes to the binary search tree. It has a
213
+ * default value of `this.iterationType`, which means it will use the iteration type specified in the
214
+ * current instance of the binary search tree
215
+ * @returns The function `addMany` returns an array of nodes (`N`) or `undefined` values.
196
216
  */
197
217
  override addMany(
198
218
  keysOrNodes: (BTNKey | N | undefined)[],
@@ -274,16 +294,21 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
274
294
  }
275
295
 
276
296
  /**
277
- * The function `lastKey` returns the key of the rightmost node if the comparison result is less
278
- * than, the key of the leftmost node if the comparison result is greater than, and the key of the
279
- * rightmost node otherwise.
280
- * @param {N | undefined} beginRoot - The `beginRoot` parameter is the starting point for finding the last
281
- * key in a binary tree. It represents the root node of the subtree from which the search for the
282
- * last key should begin. If no specific `beginRoot` is provided, the search will start from the root
283
- * of the entire binary
297
+ * Time Complexity: O(log n) - Average case for a balanced tree.
298
+ * Space Complexity: O(1) - Constant space is used.
299
+ */
300
+
301
+ /**
302
+ * Time Complexity: O(log n) - Average case for a balanced tree.
303
+ * Space Complexity: O(1) - Constant space is used.
304
+ *
305
+ * The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
306
+ * leftmost node if the comparison result is greater than.
307
+ * @param {BTNKey | N | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
308
+ * type `BTNKey`, `N`, or `undefined`. It represents the starting point for finding the last key in
309
+ * the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).
284
310
  * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
285
- * be performed when finding the last key. It determines whether the iteration should be performed in
286
- * pre-order, in-order, or post-order.
311
+ * be performed. It can have one of the following values:
287
312
  * @returns the key of the rightmost node in the binary tree if the comparison result is less than,
288
313
  * the key of the leftmost node if the comparison result is greater than, and the key of the
289
314
  * rightmost node otherwise. If no node is found, it returns 0.
@@ -295,10 +320,18 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
295
320
  }
296
321
 
297
322
  /**
323
+ * Time Complexity: O(log n) - Average case for a balanced tree.
324
+ * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
325
+ */
326
+
327
+ /**
328
+ * Time Complexity: O(log n) - Average case for a balanced tree.
329
+ * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
330
+ *
298
331
  * The function `getNodeByKey` searches for a node in a binary tree based on a given key, using
299
332
  * either recursive or iterative methods.
300
333
  * @param {BTNKey} key - The `key` parameter is the key value that we are searching for in the tree.
301
- * It is used to find the node with the matching key value.
334
+ * It is used to identify the node that we want to retrieve.
302
335
  * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
303
336
  * type of iteration to use when searching for a node in the binary tree. It can have two possible
304
337
  * values:
@@ -344,25 +377,32 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
344
377
  }
345
378
 
346
379
  /**
347
- * The function `getNodes` retrieves nodes from a binary tree based on a given node property or key,
348
- * using either recursive or iterative traversal.
349
- * @param {ReturnType<C> | N} identifier - The `nodeProperty` parameter represents the property
350
- * of the binary tree node that you want to search for. It can be either a `BTNKey` or a
351
- * generic type `N`.
352
- * @param callback - The `callback` parameter is a function that takes a node as input and returns a
353
- * value. This value is compared with the `nodeProperty` parameter to determine if the node should be
354
- * included in the result. The default value for `callback` is `this._defaultOneParamCallback`, which is
355
- * a
356
- * @param [onlyOne=false] - A boolean value indicating whether to stop the traversal after finding
357
- * the first node that matches the nodeProperty. If set to true, the function will return an array
358
- * containing only that node. If set to false (default), the function will continue the traversal and
359
- * return an array containing all nodes that match the node
360
- * @param {N | undefined} beginRoot - The `beginRoot` parameter is the starting node for the traversal. It
361
- * specifies the root node of the binary tree from which the traversal should begin. If `beginRoot`
362
- * is `undefined`, an empty array will be returned.
363
- * @param iterationType - The `iterationType` parameter determines the type of iteration used to
364
- * traverse the binary tree. It can have one of the following values:
365
- * @returns an array of nodes (N[]).
380
+ * Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
381
+ * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
382
+ */
383
+
384
+ /**
385
+ * Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
386
+ * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
387
+ *
388
+ * The function `getNodes` returns an array of nodes that match a given identifier, using either a
389
+ * recursive or iterative approach.
390
+ * @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value that you
391
+ * want to search for in the nodes of the binary tree. It can be of any type that is returned by the
392
+ * callback function `C`.
393
+ * @param {C} callback - The `callback` parameter is a function that takes a node of type `N` as its
394
+ * argument and returns a value of type `ReturnType<C>`. The `C` type parameter represents a callback
395
+ * function type that extends the `BTNCallback<N>` type. The `BTNCallback<N>` type is
396
+ * @param [onlyOne=false] - A boolean flag indicating whether to stop searching after finding the
397
+ * first node that matches the identifier. If set to true, the function will return an array
398
+ * containing only the first matching node. If set to false (default), the function will continue
399
+ * searching for all nodes that match the identifier and return an array containing
400
+ * @param {BTNKey | N | undefined} beginRoot - The `beginRoot` parameter represents the starting node
401
+ * for the traversal. It can be either a key value or a node object. If it is undefined, the
402
+ * traversal will start from the root of the tree.
403
+ * @param iterationType - The `iterationType` parameter determines the type of iteration to be
404
+ * performed on the binary tree. It can have two possible values:
405
+ * @returns The method returns an array of nodes (`N[]`).
366
406
  */
367
407
  override getNodes<C extends BTNCallback<N>>(
368
408
  identifier: ReturnType<C> | undefined,
@@ -420,24 +460,31 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
420
460
  return ans;
421
461
  }
422
462
 
423
- // --- start additional functions
463
+ /**
464
+ * Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
465
+ * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
466
+ */
424
467
 
425
468
  /**
426
- * The `lesserOrGreaterTraverse` function traverses a binary tree and applies a callback function to
427
- * nodes that have a key value lesser or greater than a target key value.
428
- * @param callback - The `callback` parameter is a function that will be called for each node that
429
- * meets the condition specified by the `lesserOrGreater` parameter. It takes a node as an argument
430
- * and returns a value.
469
+ * Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
470
+ * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
471
+ *
472
+ * The `lesserOrGreaterTraverse` function traverses a binary tree and returns an array of nodes that
473
+ * are either lesser or greater than a target node, depending on the specified comparison type.
474
+ * @param {C} callback - The `callback` parameter is a function that will be called for each node
475
+ * that satisfies the condition specified by the `lesserOrGreater` parameter. It takes a single
476
+ * parameter of type `N` (the node type) and returns a value of any type.
431
477
  * @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
432
- * traverse nodes that are lesser than, greater than, or equal to the `targetNode`. It can take one
433
- * of the following values:
434
- * @param {BTNKey | N | undefined} targetNode - The `targetNode` parameter in the
435
- * `lesserOrGreaterTraverse` function is used to specify the node from which the traversal should
436
- * start. It can be either a reference to a specific node (`N`), the key of a node
437
- * (`BTNKey`), or `undefined` to
438
- * @param iterationType - The `iterationType` parameter determines whether the traversal should be
439
- * done recursively or iteratively. It can have two possible values:
440
- * @returns The function `lesserOrGreaterTraverse` returns an array of `ReturnType<BTNCallback<N>>`.
478
+ * traverse nodes that are lesser than, greater than, or equal to the `targetNode`. It is of type
479
+ * `CP`, which is a custom type representing the comparison operator. The possible values for
480
+ * `lesserOrGreater` are
481
+ * @param {BTNKey | N | undefined} targetNode - The `targetNode` parameter represents the node in the
482
+ * binary tree that you want to traverse from. It can be specified either by its key, by the node
483
+ * object itself, or it can be left undefined to start the traversal from the root of the tree.
484
+ * @param iterationType - The `iterationType` parameter determines the type of traversal to be
485
+ * performed on the binary tree. It can have two possible values:
486
+ * @returns The function `lesserOrGreaterTraverse` returns an array of values of type
487
+ * `ReturnType<C>`, which is the return type of the callback function passed as an argument.
441
488
  */
442
489
  lesserOrGreaterTraverse<C extends BTNCallback<N>>(
443
490
  callback: C = this._defaultOneParamCallback as C,
@@ -491,6 +538,14 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
491
538
  */
492
539
 
493
540
  /**
541
+ * Time Complexity: O(n) - Building a balanced tree from a sorted array.
542
+ * Space Complexity: O(n) - Additional space is required for the sorted array.
543
+ */
544
+
545
+ /**
546
+ * Time Complexity: O(n) - Building a balanced tree from a sorted array.
547
+ * Space Complexity: O(n) - Additional space is required for the sorted array.
548
+ *
494
549
  * The `perfectlyBalance` function balances a binary search tree by adding nodes in a way that
495
550
  * ensures the tree is perfectly balanced.
496
551
  * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
@@ -537,6 +592,14 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
537
592
  }
538
593
 
539
594
  /**
595
+ * Time Complexity: O(n) - Visiting each node once.
596
+ * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
597
+ */
598
+
599
+ /**
600
+ * Time Complexity: O(n) - Visiting each node once.
601
+ * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
602
+ *
540
603
  * The function checks if a binary tree is AVL balanced using either recursive or iterative approach.
541
604
  * @param iterationType - The `iterationType` parameter is used to determine the method of iteration
542
605
  * to check if the AVL tree is balanced. It can have two possible values:
@@ -610,5 +673,4 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
610
673
  else return CP.eq;
611
674
  }
612
675
 
613
- // --- end additional functions
614
676
  }
@@ -39,6 +39,11 @@ export class RedBlackTree<V = any, N extends RedBlackTreeNode<V, N> = RedBlackTr
39
39
  implements IBinaryTree<V, N>
40
40
  {
41
41
 
42
+ /**
43
+ * The constructor function initializes a Red-Black Tree with an optional set of options.
44
+ * @param {RBTreeOptions} [options] - The `options` parameter is an optional object that can be
45
+ * passed to the constructor. It is used to configure the RBTree object with specific options.
46
+ */
42
47
  constructor(options?: RBTreeOptions) {
43
48
  super(options);
44
49
  this._root = this.NIL;
@@ -59,6 +64,14 @@ export class RedBlackTree<V = any, N extends RedBlackTreeNode<V, N> = RedBlackTr
59
64
  NIL: N = new RedBlackTreeNode<V>(NaN) as unknown as N;
60
65
 
61
66
  /**
67
+ * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
68
+ * Space Complexity: O(1)
69
+ */
70
+
71
+ /**
72
+ * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
73
+ * Space Complexity: O(1)
74
+ *
62
75
  * The `add` function adds a new node to a Red-Black Tree data structure.
63
76
  * @param {BTNKey | N | null | undefined} keyOrNode - The `keyOrNode` parameter can be one of the
64
77
  * following types:
@@ -122,8 +135,16 @@ export class RedBlackTree<V = any, N extends RedBlackTreeNode<V, N> = RedBlackTr
122
135
  override createNode(key: BTNKey, value?: V, color: RBTNColor = RBTNColor.BLACK): N {
123
136
  return new RedBlackTreeNode<V, N>(key, value, color) as N;
124
137
  }
125
-
138
+
139
+ /**
140
+ * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
141
+ * Space Complexity: O(1)
142
+ */
143
+
126
144
  /**
145
+ * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
146
+ * Space Complexity: O(1)
147
+ *
127
148
  * The `delete` function removes a node from a binary tree based on a given identifier and updates
128
149
  * the tree accordingly.
129
150
  * @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is the value
@@ -222,19 +243,30 @@ export class RedBlackTree<V = any, N extends RedBlackTreeNode<V, N> = RedBlackTr
222
243
  ): N | undefined;
223
244
 
224
245
  /**
225
- * The function `get` returns the first node in a binary tree that matches the given property or key.
226
- * @param {BTNKey | N} identifier - The `identifier` parameter is the key or value of
227
- * the node that you want to find in the binary tree. It can be either a `BTNKey` or `N`
228
- * type.
229
- * @param callback - The `callback` parameter is a function that is used to determine whether a node
230
- * matches the desired criteria. It takes a node as input and returns a boolean value indicating
231
- * whether the node matches the criteria or not. The default callback function
232
- * (`this._defaultOneParamCallback`) is used if no callback function is
233
- * @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
234
- * the root node from which the search should begin.
235
- * @param iterationType - The `iterationType` parameter specifies the type of iteration to be
236
- * performed when searching for a node in the binary tree. It can have one of the following values:
237
- * @returns either the found node (of type N) or null if no node is found.
246
+ * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
247
+ * Space Complexity: O(1)
248
+ */
249
+
250
+ /**
251
+ * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
252
+ * Space Complexity: O(1)
253
+ *
254
+ * The function `getNode` retrieves a single node from a binary tree based on a given identifier and
255
+ * callback function.
256
+ * @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value used to
257
+ * identify the node you want to retrieve. It can be of any type that is the return type of the `C`
258
+ * callback function. If the `identifier` is `undefined`, it means you want to retrieve the first
259
+ * node that matches the other criteria
260
+ * @param {C} callback - The `callback` parameter is a function that will be called for each node in
261
+ * the binary tree. It is used to determine if a node matches the given identifier. The `callback`
262
+ * function should take a single parameter of type `N` (the type of the nodes in the binary tree) and
263
+ * @param {BTNKey | N | undefined} beginRoot - The `beginRoot` parameter is the starting point for
264
+ * searching for a node in a binary tree. It can be either a key value or a node object. If it is not
265
+ * provided, the search will start from the root of the binary tree.
266
+ * @param iterationType - The `iterationType` parameter is a variable that determines the type of
267
+ * iteration to be performed when searching for nodes in the binary tree. It is used in the
268
+ * `getNodes` method, which is called within the `getNode` method.
269
+ * @returns a value of type `N`, `null`, or `undefined`.
238
270
  */
239
271
  getNode<C extends BTNCallback<N>>(
240
272
  identifier: ReturnType<C> | undefined,
@@ -248,6 +280,14 @@ export class RedBlackTree<V = any, N extends RedBlackTreeNode<V, N> = RedBlackTr
248
280
  }
249
281
 
250
282
  /**
283
+ * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
284
+ * Space Complexity: O(1)
285
+ */
286
+
287
+ /**
288
+ * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
289
+ * Space Complexity: O(1)
290
+ *
251
291
  * The function returns the successor of a given node in a red-black tree.
252
292
  * @param {RedBlackTreeNode} x - RedBlackTreeNode - The node for which we want to find the successor.
253
293
  * @returns the successor of the given RedBlackTreeNode.
@@ -266,6 +306,14 @@ export class RedBlackTree<V = any, N extends RedBlackTreeNode<V, N> = RedBlackTr
266
306
  }
267
307
 
268
308
  /**
309
+ * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
310
+ * Space Complexity: O(1)
311
+ */
312
+
313
+ /**
314
+ * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
315
+ * Space Complexity: O(1)
316
+ *
269
317
  * The function returns the predecessor of a given node in a red-black tree.
270
318
  * @param {RedBlackTreeNode} x - The parameter `x` is of type `RedBlackTreeNode`, which represents a node in a
271
319
  * Red-Black Tree.
@@ -298,8 +346,16 @@ export class RedBlackTree<V = any, N extends RedBlackTreeNode<V, N> = RedBlackTr
298
346
  }
299
347
 
300
348
  /**
301
- * The function performs a left rotation on a red-black tree node.
302
- * @param {RedBlackTreeNode} x - The parameter `x` is a RedBlackTreeNode object.
349
+ * Time Complexity: O(1)
350
+ * Space Complexity: O(1)
351
+ */
352
+
353
+ /**
354
+ * Time Complexity: O(1)
355
+ * Space Complexity: O(1)
356
+ *
357
+ * The function performs a left rotation on a binary tree node.
358
+ * @param {RedBlackTreeNode} x - The parameter `x` is of type `N`, which likely represents a node in a binary tree.
303
359
  */
304
360
  protected _leftRotate(x: N): void {
305
361
  if (x.right) {
@@ -322,6 +378,14 @@ export class RedBlackTree<V = any, N extends RedBlackTreeNode<V, N> = RedBlackTr
322
378
  }
323
379
 
324
380
  /**
381
+ * Time Complexity: O(1)
382
+ * Space Complexity: O(1)
383
+ */
384
+
385
+ /**
386
+ * Time Complexity: O(1)
387
+ * Space Complexity: O(1)
388
+ *
325
389
  * The function performs a right rotation on a red-black tree node.
326
390
  * @param {RedBlackTreeNode} x - x is a RedBlackTreeNode, which represents the node that needs to be right
327
391
  * rotated.
@@ -347,9 +411,16 @@ export class RedBlackTree<V = any, N extends RedBlackTreeNode<V, N> = RedBlackTr
347
411
  }
348
412
 
349
413
  /**
350
- * The _fixDelete function is used to rebalance the Red-Black Tree after a node deletion.
351
- * @param {RedBlackTreeNode} x - The parameter `x` is of type `RedBlackTreeNode`, which represents a node in a
352
- * red-black tree.
414
+ * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
415
+ * Space Complexity: O(1)
416
+ */
417
+
418
+ /**
419
+ * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
420
+ * Space Complexity: O(1)
421
+ *
422
+ * The function `_fixDelete` is used to fix the red-black tree after a node deletion.
423
+ * @param {RedBlackTreeNode} x - The parameter `x` represents a node in a Red-Black Tree (RBT).
353
424
  */
354
425
  protected _fixDelete(x: N): void {
355
426
  let s: N | undefined;
@@ -412,6 +483,14 @@ export class RedBlackTree<V = any, N extends RedBlackTreeNode<V, N> = RedBlackTr
412
483
  }
413
484
 
414
485
  /**
486
+ * Time Complexity: O(1)
487
+ * Space Complexity: O(1)
488
+ */
489
+
490
+ /**
491
+ * Time Complexity: O(1)
492
+ * Space Complexity: O(1)
493
+ *
415
494
  * The function `_rbTransplant` replaces one node in a red-black tree with another node.
416
495
  * @param {RedBlackTreeNode} u - The parameter "u" represents a RedBlackTreeNode object.
417
496
  * @param {RedBlackTreeNode} v - The parameter "v" is a RedBlackTreeNode object.
@@ -428,6 +507,14 @@ export class RedBlackTree<V = any, N extends RedBlackTreeNode<V, N> = RedBlackTr
428
507
  }
429
508
 
430
509
  /**
510
+ * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
511
+ * Space Complexity: O(1)
512
+ */
513
+
514
+ /**
515
+ * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
516
+ * Space Complexity: O(1)
517
+ *
431
518
  * The `_fixInsert` function is used to fix the red-black tree after an insertion operation.
432
519
  * @param {RedBlackTreeNode} k - The parameter `k` is a RedBlackTreeNode object, which represents a node in a
433
520
  * red-black tree.