min-heap-typed 1.42.8 → 1.43.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 (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 +415 -236
  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 +465 -256
  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
@@ -47,13 +47,21 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
47
47
  }
48
48
 
49
49
  /**
50
- * The function overrides the add method of a binary tree node and balances the tree after inserting
51
- * a new node.
52
- * @param {BTNKey | N | undefined} keyOrNode - The `keyOrNode` parameter can accept either a
53
- * `BTNKey` or a `N` (which represents a node in the binary tree) or `null`.
54
- * @param [value] - The `value` parameter is the value that you want to assign to the new node that you
55
- * are adding to the binary search tree.
56
- * @returns The method is returning the inserted node (`N`), `null`, or `undefined`.
50
+ * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
51
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
52
+ */
53
+
54
+ /**
55
+ * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
56
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
57
+ *
58
+ * The function overrides the add method of a class, adds a key-value pair to a data structure, and
59
+ * balances the structure if necessary.
60
+ * @param {BTNKey | N | null | undefined} keyOrNode - The `keyOrNode` parameter can be of type
61
+ * `BTNKey`, `N`, `null`, or `undefined`.
62
+ * @param {V} [value] - The `value` parameter is the value associated with the key that is being
63
+ * added to the binary search tree.
64
+ * @returns The method is returning either a node (N) or undefined.
57
65
  */
58
66
  override add(keyOrNode: BTNKey | N | null | undefined, value?: V): N | undefined {
59
67
  if (keyOrNode === null) return undefined;
@@ -63,16 +71,24 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
63
71
  }
64
72
 
65
73
  /**
66
- * The function overrides the delete method of a binary tree and balances the tree after deleting a
67
- * node if necessary.
68
- * @param {ReturnType<C>} identifier - The `identifier` parameter is either a
69
- * `BTNKey` or a generic type `N`. It represents the property of the node that we are
70
- * searching for. It can be a specific key value or any other property of the node.
71
- * @param callback - The `callback` parameter is a function that takes a node as input and returns a
72
- * value. This value is compared with the `identifier` parameter to determine if the node should be
73
- * included in the result. The `callback` parameter has a default value of
74
- * `this._defaultOneParamCallback`
75
- * @returns The method is returning an array of `BiTreeDeleteResult<N>` objects.
74
+ * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (BST) has logarithmic time complexity.
75
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
76
+ */
77
+
78
+ /**
79
+ * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (BST) has logarithmic time complexity.
80
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
81
+ *
82
+ * The function overrides the delete method of a binary tree, performs the deletion, and then
83
+ * balances the tree if necessary.
84
+ * @param identifier - The `identifier` parameter is the value or condition used to identify the
85
+ * node(s) to be deleted from the binary tree. It can be of any type and is the return type of the
86
+ * `callback` function.
87
+ * @param {C} callback - The `callback` parameter is a function that will be called for each node
88
+ * that is deleted from the binary tree. It is an optional parameter and if not provided, it will
89
+ * default to the `_defaultOneParamCallback` function. The `callback` function should have a single
90
+ * parameter of type `N
91
+ * @returns The method is returning an array of `BiTreeDeleteResult<N>`.
76
92
  */
77
93
  override delete<C extends BTNCallback<N>>(
78
94
  identifier: ReturnType<C>,
@@ -89,12 +105,14 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
89
105
  }
90
106
 
91
107
  /**
92
- * The function swaps the key, value, and height properties between two nodes in a binary tree.
93
- * @param {N} srcNode - The `srcNode` parameter represents the source node that needs to be swapped
94
- * with the `destNode`.
95
- * @param {N} destNode - The `destNode` parameter represents the destination node where the values
96
- * from the source node (`srcNode`) will be swapped to.
97
- * @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
108
+ * The `_swap` function swaps the key, value, and height properties between two nodes in a binary
109
+ * tree.
110
+ * @param {BTNKey | N | undefined} srcNode - The `srcNode` parameter represents the source node that
111
+ * needs to be swapped with the destination node. It can be of type `BTNKey`, `N`, or `undefined`.
112
+ * @param {BTNKey | N | undefined} destNode - The `destNode` parameter represents the destination
113
+ * node where the values from the source node will be swapped to.
114
+ * @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
115
+ * if either `srcNode` or `destNode` is undefined.
98
116
  */
99
117
  protected override _swap(srcNode: BTNKey | N | undefined, destNode: BTNKey | N | undefined): N | undefined {
100
118
  srcNode = this.ensureNotKey(srcNode);
@@ -122,6 +140,14 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
122
140
  }
123
141
 
124
142
  /**
143
+ * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
144
+ * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
145
+ */
146
+
147
+ /**
148
+ * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
149
+ * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
150
+ *
125
151
  * The function calculates the balance factor of a node in a binary tree.
126
152
  * @param {N} node - The parameter "node" represents a node in a binary tree data structure.
127
153
  * @returns the balance factor of a given node. The balance factor is calculated by subtracting the
@@ -138,6 +164,14 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
138
164
  }
139
165
 
140
166
  /**
167
+ * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
168
+ * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
169
+ */
170
+
171
+ /**
172
+ * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
173
+ * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
174
+ *
141
175
  * The function updates the height of a node in a binary tree based on the heights of its left and
142
176
  * right children.
143
177
  * @param {N} node - The parameter "node" represents a node in a binary tree data structure.
@@ -152,6 +186,14 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
152
186
  }
153
187
 
154
188
  /**
189
+ * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root.
190
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
191
+ */
192
+
193
+ /**
194
+ * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root.
195
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
196
+ *
155
197
  * The `_balancePath` function is used to update the heights of nodes and perform rotation operations
156
198
  * to restore balance in an AVL tree after inserting a node.
157
199
  * @param {N} node - The `node` parameter in the `_balancePath` function represents the node in the
@@ -197,6 +239,14 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
197
239
  }
198
240
 
199
241
  /**
242
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
243
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
244
+ */
245
+
246
+ /**
247
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
248
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
249
+ *
200
250
  * The function `_balanceLL` performs a left-left rotation to balance a binary tree.
201
251
  * @param {N} A - A is a node in a binary tree.
202
252
  */
@@ -227,6 +277,14 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
227
277
  }
228
278
 
229
279
  /**
280
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
281
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
282
+ */
283
+
284
+ /**
285
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
286
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
287
+ *
230
288
  * The `_balanceLR` function performs a left-right rotation to balance a binary tree.
231
289
  * @param {N} A - A is a node in a binary tree.
232
290
  */
@@ -275,6 +333,14 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
275
333
  }
276
334
 
277
335
  /**
336
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
337
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
338
+ */
339
+
340
+ /**
341
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
342
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
343
+ *
278
344
  * The function `_balanceRR` performs a right-right rotation to balance a binary tree.
279
345
  * @param {N} A - A is a node in a binary tree.
280
346
  */
@@ -310,6 +376,14 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
310
376
  }
311
377
 
312
378
  /**
379
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
380
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
381
+ */
382
+
383
+ /**
384
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
385
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
386
+ *
313
387
  * The function `_balanceRL` performs a right-left rotation to balance a binary tree.
314
388
  * @param {N} A - A is a node in a binary tree.
315
389
  */