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
@@ -32,38 +32,61 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
32
32
  */
33
33
  createNode(key: BTNKey, value?: V): N;
34
34
  /**
35
- * The function overrides the add method of a binary tree node and balances the tree after inserting
36
- * a new node.
37
- * @param {BTNKey | N | undefined} keyOrNode - The `keyOrNode` parameter can accept either a
38
- * `BTNKey` or a `N` (which represents a node in the binary tree) or `null`.
39
- * @param [value] - The `value` parameter is the value that you want to assign to the new node that you
40
- * are adding to the binary search tree.
41
- * @returns The method is returning the inserted node (`N`), `null`, or `undefined`.
35
+ * 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.
36
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
37
+ */
38
+ /**
39
+ * 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.
40
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
41
+ *
42
+ * The function overrides the add method of a class, adds a key-value pair to a data structure, and
43
+ * balances the structure if necessary.
44
+ * @param {BTNKey | N | null | undefined} keyOrNode - The `keyOrNode` parameter can be of type
45
+ * `BTNKey`, `N`, `null`, or `undefined`.
46
+ * @param {V} [value] - The `value` parameter is the value associated with the key that is being
47
+ * added to the binary search tree.
48
+ * @returns The method is returning either a node (N) or undefined.
42
49
  */
43
50
  add(keyOrNode: BTNKey | N | null | undefined, value?: V): N | undefined;
44
51
  /**
45
- * The function overrides the delete method of a binary tree and balances the tree after deleting a
46
- * node if necessary.
47
- * @param {ReturnType<C>} identifier - The `identifier` parameter is either a
48
- * `BTNKey` or a generic type `N`. It represents the property of the node that we are
49
- * searching for. It can be a specific key value or any other property of the node.
50
- * @param callback - The `callback` parameter is a function that takes a node as input and returns a
51
- * value. This value is compared with the `identifier` parameter to determine if the node should be
52
- * included in the result. The `callback` parameter has a default value of
53
- * `this._defaultOneParamCallback`
54
- * @returns The method is returning an array of `BiTreeDeleteResult<N>` objects.
52
+ * 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.
53
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
54
+ */
55
+ /**
56
+ * 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.
57
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
58
+ *
59
+ * The function overrides the delete method of a binary tree, performs the deletion, and then
60
+ * balances the tree if necessary.
61
+ * @param identifier - The `identifier` parameter is the value or condition used to identify the
62
+ * node(s) to be deleted from the binary tree. It can be of any type and is the return type of the
63
+ * `callback` function.
64
+ * @param {C} callback - The `callback` parameter is a function that will be called for each node
65
+ * that is deleted from the binary tree. It is an optional parameter and if not provided, it will
66
+ * default to the `_defaultOneParamCallback` function. The `callback` function should have a single
67
+ * parameter of type `N
68
+ * @returns The method is returning an array of `BiTreeDeleteResult<N>`.
55
69
  */
56
70
  delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback?: C): BiTreeDeleteResult<N>[];
57
71
  /**
58
- * The function swaps the key, value, and height properties between two nodes in a binary tree.
59
- * @param {N} srcNode - The `srcNode` parameter represents the source node that needs to be swapped
60
- * with the `destNode`.
61
- * @param {N} destNode - The `destNode` parameter represents the destination node where the values
62
- * from the source node (`srcNode`) will be swapped to.
63
- * @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
72
+ * The `_swap` function swaps the key, value, and height properties between two nodes in a binary
73
+ * tree.
74
+ * @param {BTNKey | N | undefined} srcNode - The `srcNode` parameter represents the source node that
75
+ * needs to be swapped with the destination node. It can be of type `BTNKey`, `N`, or `undefined`.
76
+ * @param {BTNKey | N | undefined} destNode - The `destNode` parameter represents the destination
77
+ * node where the values from the source node will be swapped to.
78
+ * @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
79
+ * if either `srcNode` or `destNode` is undefined.
64
80
  */
65
81
  protected _swap(srcNode: BTNKey | N | undefined, destNode: BTNKey | N | undefined): N | undefined;
66
82
  /**
83
+ * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
84
+ * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
85
+ */
86
+ /**
87
+ * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
88
+ * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
89
+ *
67
90
  * The function calculates the balance factor of a node in a binary tree.
68
91
  * @param {N} node - The parameter "node" represents a node in a binary tree data structure.
69
92
  * @returns the balance factor of a given node. The balance factor is calculated by subtracting the
@@ -71,12 +94,26 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
71
94
  */
72
95
  protected _balanceFactor(node: N): number;
73
96
  /**
97
+ * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
98
+ * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
99
+ */
100
+ /**
101
+ * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
102
+ * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
103
+ *
74
104
  * The function updates the height of a node in a binary tree based on the heights of its left and
75
105
  * right children.
76
106
  * @param {N} node - The parameter "node" represents a node in a binary tree data structure.
77
107
  */
78
108
  protected _updateHeight(node: N): void;
79
109
  /**
110
+ * 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.
111
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
112
+ */
113
+ /**
114
+ * 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.
115
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
116
+ *
80
117
  * The `_balancePath` function is used to update the heights of nodes and perform rotation operations
81
118
  * to restore balance in an AVL tree after inserting a node.
82
119
  * @param {N} node - The `node` parameter in the `_balancePath` function represents the node in the
@@ -84,21 +121,49 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
84
121
  */
85
122
  protected _balancePath(node: N): void;
86
123
  /**
124
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
125
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
126
+ */
127
+ /**
128
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
129
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
130
+ *
87
131
  * The function `_balanceLL` performs a left-left rotation to balance a binary tree.
88
132
  * @param {N} A - A is a node in a binary tree.
89
133
  */
90
134
  protected _balanceLL(A: N): void;
91
135
  /**
136
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
137
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
138
+ */
139
+ /**
140
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
141
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
142
+ *
92
143
  * The `_balanceLR` function performs a left-right rotation to balance a binary tree.
93
144
  * @param {N} A - A is a node in a binary tree.
94
145
  */
95
146
  protected _balanceLR(A: N): void;
96
147
  /**
148
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
149
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
150
+ */
151
+ /**
152
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
153
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
154
+ *
97
155
  * The function `_balanceRR` performs a right-right rotation to balance a binary tree.
98
156
  * @param {N} A - A is a node in a binary tree.
99
157
  */
100
158
  protected _balanceRR(A: N): void;
101
159
  /**
160
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
161
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
162
+ */
163
+ /**
164
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
165
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
166
+ *
102
167
  * The function `_balanceRL` performs a right-left rotation to balance a binary tree.
103
168
  * @param {N} A - A is a node in a binary tree.
104
169
  */
@@ -39,13 +39,20 @@ class AVLTree extends bst_1.BST {
39
39
  return new AVLTreeNode(key, value);
40
40
  }
41
41
  /**
42
- * The function overrides the add method of a binary tree node and balances the tree after inserting
43
- * a new node.
44
- * @param {BTNKey | N | undefined} keyOrNode - The `keyOrNode` parameter can accept either a
45
- * `BTNKey` or a `N` (which represents a node in the binary tree) or `null`.
46
- * @param [value] - The `value` parameter is the value that you want to assign to the new node that you
47
- * are adding to the binary search tree.
48
- * @returns The method is returning the inserted node (`N`), `null`, or `undefined`.
42
+ * 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.
43
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
44
+ */
45
+ /**
46
+ * 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.
47
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
48
+ *
49
+ * The function overrides the add method of a class, adds a key-value pair to a data structure, and
50
+ * balances the structure if necessary.
51
+ * @param {BTNKey | N | null | undefined} keyOrNode - The `keyOrNode` parameter can be of type
52
+ * `BTNKey`, `N`, `null`, or `undefined`.
53
+ * @param {V} [value] - The `value` parameter is the value associated with the key that is being
54
+ * added to the binary search tree.
55
+ * @returns The method is returning either a node (N) or undefined.
49
56
  */
50
57
  add(keyOrNode, value) {
51
58
  if (keyOrNode === null)
@@ -56,16 +63,23 @@ class AVLTree extends bst_1.BST {
56
63
  return inserted;
57
64
  }
58
65
  /**
59
- * The function overrides the delete method of a binary tree and balances the tree after deleting a
60
- * node if necessary.
61
- * @param {ReturnType<C>} identifier - The `identifier` parameter is either a
62
- * `BTNKey` or a generic type `N`. It represents the property of the node that we are
63
- * searching for. It can be a specific key value or any other property of the node.
64
- * @param callback - The `callback` parameter is a function that takes a node as input and returns a
65
- * value. This value is compared with the `identifier` parameter to determine if the node should be
66
- * included in the result. The `callback` parameter has a default value of
67
- * `this._defaultOneParamCallback`
68
- * @returns The method is returning an array of `BiTreeDeleteResult<N>` objects.
66
+ * 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.
67
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
68
+ */
69
+ /**
70
+ * 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.
71
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
72
+ *
73
+ * The function overrides the delete method of a binary tree, performs the deletion, and then
74
+ * balances the tree if necessary.
75
+ * @param identifier - The `identifier` parameter is the value or condition used to identify the
76
+ * node(s) to be deleted from the binary tree. It can be of any type and is the return type of the
77
+ * `callback` function.
78
+ * @param {C} callback - The `callback` parameter is a function that will be called for each node
79
+ * that is deleted from the binary tree. It is an optional parameter and if not provided, it will
80
+ * default to the `_defaultOneParamCallback` function. The `callback` function should have a single
81
+ * parameter of type `N
82
+ * @returns The method is returning an array of `BiTreeDeleteResult<N>`.
69
83
  */
70
84
  delete(identifier, callback = this._defaultOneParamCallback) {
71
85
  if (identifier instanceof AVLTreeNode)
@@ -79,12 +93,14 @@ class AVLTree extends bst_1.BST {
79
93
  return deletedResults;
80
94
  }
81
95
  /**
82
- * The function swaps the key, value, and height properties between two nodes in a binary tree.
83
- * @param {N} srcNode - The `srcNode` parameter represents the source node that needs to be swapped
84
- * with the `destNode`.
85
- * @param {N} destNode - The `destNode` parameter represents the destination node where the values
86
- * from the source node (`srcNode`) will be swapped to.
87
- * @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
96
+ * The `_swap` function swaps the key, value, and height properties between two nodes in a binary
97
+ * tree.
98
+ * @param {BTNKey | N | undefined} srcNode - The `srcNode` parameter represents the source node that
99
+ * needs to be swapped with the destination node. It can be of type `BTNKey`, `N`, or `undefined`.
100
+ * @param {BTNKey | N | undefined} destNode - The `destNode` parameter represents the destination
101
+ * node where the values from the source node will be swapped to.
102
+ * @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
103
+ * if either `srcNode` or `destNode` is undefined.
88
104
  */
89
105
  _swap(srcNode, destNode) {
90
106
  srcNode = this.ensureNotKey(srcNode);
@@ -106,6 +122,13 @@ class AVLTree extends bst_1.BST {
106
122
  return undefined;
107
123
  }
108
124
  /**
125
+ * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
126
+ * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
127
+ */
128
+ /**
129
+ * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
130
+ * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
131
+ *
109
132
  * The function calculates the balance factor of a node in a binary tree.
110
133
  * @param {N} node - The parameter "node" represents a node in a binary tree data structure.
111
134
  * @returns the balance factor of a given node. The balance factor is calculated by subtracting the
@@ -122,6 +145,13 @@ class AVLTree extends bst_1.BST {
122
145
  return node.right.height - node.left.height;
123
146
  }
124
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
+ */
151
+ /**
152
+ * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
153
+ * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
154
+ *
125
155
  * The function updates the height of a node in a binary tree based on the heights of its left and
126
156
  * right children.
127
157
  * @param {N} node - The parameter "node" represents a node in a binary tree data structure.
@@ -139,6 +169,13 @@ class AVLTree extends bst_1.BST {
139
169
  node.height = 1 + Math.max(node.right.height, node.left.height);
140
170
  }
141
171
  /**
172
+ * 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.
173
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
174
+ */
175
+ /**
176
+ * 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.
177
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
178
+ *
142
179
  * The `_balancePath` function is used to update the heights of nodes and perform rotation operations
143
180
  * to restore balance in an AVL tree after inserting a node.
144
181
  * @param {N} node - The `node` parameter in the `_balancePath` function represents the node in the
@@ -184,6 +221,13 @@ class AVLTree extends bst_1.BST {
184
221
  }
185
222
  }
186
223
  /**
224
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
225
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
226
+ */
227
+ /**
228
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
229
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
230
+ *
187
231
  * The function `_balanceLL` performs a left-left rotation to balance a binary tree.
188
232
  * @param {N} A - A is a node in a binary tree.
189
233
  */
@@ -218,6 +262,13 @@ class AVLTree extends bst_1.BST {
218
262
  this._updateHeight(B);
219
263
  }
220
264
  /**
265
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
266
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
267
+ */
268
+ /**
269
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
270
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
271
+ *
221
272
  * The `_balanceLR` function performs a left-right rotation to balance a binary tree.
222
273
  * @param {N} A - A is a node in a binary tree.
223
274
  */
@@ -267,6 +318,13 @@ class AVLTree extends bst_1.BST {
267
318
  C && this._updateHeight(C);
268
319
  }
269
320
  /**
321
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
322
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
323
+ */
324
+ /**
325
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
326
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
327
+ *
270
328
  * The function `_balanceRR` performs a right-right rotation to balance a binary tree.
271
329
  * @param {N} A - A is a node in a binary tree.
272
330
  */
@@ -302,6 +360,13 @@ class AVLTree extends bst_1.BST {
302
360
  B && this._updateHeight(B);
303
361
  }
304
362
  /**
363
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
364
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
365
+ */
366
+ /**
367
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
368
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
369
+ *
305
370
  * The function `_balanceRL` performs a right-left rotation to balance a binary tree.
306
371
  * @param {N} A - A is a node in a binary tree.
307
372
  */