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
@@ -27,6 +27,13 @@ export declare class SinglyLinkedList<E = any> {
27
27
  protected _length: number;
28
28
  get length(): number;
29
29
  /**
30
+ * Time Complexity: O(n) - Linear time, where n is the length of the input array, as it performs a loop to push each element into the linked list.
31
+ * Space Complexity: O(n) - Linear space, as it creates a new node for each element in the array.
32
+ */
33
+ /**
34
+ * Time Complexity: O(n) - Linear time, where n is the length of the input array, as it performs a loop to push each element into the linked list.
35
+ * Space Complexity: O(n) - Linear space, as it creates a new node for each element in the array.
36
+ *
30
37
  * The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
31
38
  * array.
32
39
  * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
@@ -34,18 +41,39 @@ export declare class SinglyLinkedList<E = any> {
34
41
  */
35
42
  static fromArray<E>(data: E[]): SinglyLinkedList<E>;
36
43
  /**
44
+ * Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
45
+ * Space Complexity: O(1) - Constant space, as it only creates a new node.
46
+ */
47
+ /**
48
+ * Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
49
+ * Space Complexity: O(1) - Constant space, as it only creates a new node.
50
+ *
37
51
  * The `push` function adds a new node with the given value to the end of a singly linked list.
38
52
  * @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
39
53
  * any type (E) as specified in the generic type declaration of the class or function.
40
54
  */
41
55
  push(value: E): void;
42
56
  /**
57
+ * Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
58
+ * Space Complexity: O(1) - Constant space, as it only creates a new node.
59
+ */
60
+ /**
61
+ * Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
62
+ * Space Complexity: O(1) - Constant space, as it only creates a new node.
63
+ *
43
64
  * The `push` function adds a new node with the given value to the end of a singly linked list.
44
65
  * @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
45
66
  * any type (E) as specified in the generic type declaration of the class or function.
46
67
  */
47
68
  addLast(value: E): void;
48
69
  /**
70
+ * Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
71
+ * Space Complexity: O(1) - Constant space.
72
+ */
73
+ /**
74
+ * Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
75
+ * Space Complexity: O(1) - Constant space.
76
+ *
49
77
  * The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail
50
78
  * pointers accordingly.
51
79
  * @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
@@ -53,6 +81,13 @@ export declare class SinglyLinkedList<E = any> {
53
81
  */
54
82
  pop(): E | undefined;
55
83
  /**
84
+ * Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
85
+ * Space Complexity: O(1) - Constant space.
86
+ */
87
+ /**
88
+ * Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
89
+ * Space Complexity: O(1) - Constant space.
90
+ *
56
91
  * The `popLast()` function removes and returns the value of the last element in a linked list, updating the head and tail
57
92
  * pointers accordingly.
58
93
  * @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
@@ -60,28 +95,63 @@ export declare class SinglyLinkedList<E = any> {
60
95
  */
61
96
  popLast(): E | undefined;
62
97
  /**
98
+ * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
99
+ * Space Complexity: O(1) - Constant space.
100
+ */
101
+ /**
102
+ * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
103
+ * Space Complexity: O(1) - Constant space.
104
+ *
63
105
  * The `shift()` function removes and returns the value of the first node in a linked list.
64
106
  * @returns The value of the node that is being removed from the beginning of the linked list.
65
107
  */
66
108
  shift(): E | undefined;
67
109
  /**
110
+ * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
111
+ * Space Complexity: O(1) - Constant space.
112
+ */
113
+ /**
114
+ * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
115
+ * Space Complexity: O(1) - Constant space.
116
+ *
68
117
  * The `popFirst()` function removes and returns the value of the first node in a linked list.
69
118
  * @returns The value of the node that is being removed from the beginning of the linked list.
70
119
  */
71
120
  popFirst(): E | undefined;
72
121
  /**
122
+ * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
123
+ * Space Complexity: O(1) - Constant space.
124
+ */
125
+ /**
126
+ * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
127
+ * Space Complexity: O(1) - Constant space.
128
+ *
73
129
  * The unshift function adds a new node with the given value to the beginning of a singly linked list.
74
130
  * @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
75
131
  * linked list.
76
132
  */
77
133
  unshift(value: E): void;
78
134
  /**
135
+ * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
136
+ * Space Complexity: O(1) - Constant space.
137
+ */
138
+ /**
139
+ * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
140
+ * Space Complexity: O(1) - Constant space.
141
+ *
79
142
  * The addFirst function adds a new node with the given value to the beginning of a singly linked list.
80
143
  * @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
81
144
  * linked list.
82
145
  */
83
146
  addFirst(value: E): void;
84
147
  /**
148
+ * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
149
+ * Space Complexity: O(1) - Constant space.
150
+ */
151
+ /**
152
+ * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
153
+ * Space Complexity: O(1) - Constant space.
154
+ *
85
155
  * The function `getAt` returns the value at a specified index in a linked list, or null if the index is out of range.
86
156
  * @param {number} index - The index parameter is a number that represents the position of the element we want to
87
157
  * retrieve from the list.
@@ -90,6 +160,13 @@ export declare class SinglyLinkedList<E = any> {
90
160
  */
91
161
  getAt(index: number): E | undefined;
92
162
  /**
163
+ * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
164
+ * Space Complexity: O(1) - Constant space.
165
+ */
166
+ /**
167
+ * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
168
+ * Space Complexity: O(1) - Constant space.
169
+ *
93
170
  * The function `getNodeAt` returns the node at a given index in a singly linked list.
94
171
  * @param {number} index - The `index` parameter is a number that represents the position of the node we want to
95
172
  * retrieve from the linked list. It indicates the zero-based index of the node we want to access.
@@ -98,6 +175,13 @@ export declare class SinglyLinkedList<E = any> {
98
175
  */
99
176
  getNodeAt(index: number): SinglyLinkedListNode<E> | null;
100
177
  /**
178
+ * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
179
+ * Space Complexity: O(1) - Constant space.
180
+ */
181
+ /**
182
+ * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
183
+ * Space Complexity: O(1) - Constant space.
184
+ *
101
185
  * The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
102
186
  * @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
103
187
  * data structure. It is of type number.
@@ -106,6 +190,13 @@ export declare class SinglyLinkedList<E = any> {
106
190
  */
107
191
  deleteAt(index: number): E | undefined;
108
192
  /**
193
+ * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
194
+ * Space Complexity: O(1) - Constant space.
195
+ */
196
+ /**
197
+ * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
198
+ * Space Complexity: O(1) - Constant space.
199
+ *
109
200
  * The delete function removes a node with a specific value from a singly linked list.
110
201
  * @param {E | SinglyLinkedListNode<E>} valueOrNode - The `valueOrNode` parameter can accept either a value of type `E`
111
202
  * or a `SinglyLinkedListNode<E>` object.
@@ -114,6 +205,13 @@ export declare class SinglyLinkedList<E = any> {
114
205
  */
115
206
  delete(valueOrNode: E | SinglyLinkedListNode<E> | null | undefined): boolean;
116
207
  /**
208
+ * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
209
+ * Space Complexity: O(1) - Constant space.
210
+ */
211
+ /**
212
+ * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
213
+ * Space Complexity: O(1) - Constant space.
214
+ *
117
215
  * The `insertAt` function inserts a value at a specified index in a singly linked list.
118
216
  * @param {number} index - The index parameter represents the position at which the new value should be inserted in the
119
217
  * linked list. It is of type number.
@@ -134,16 +232,37 @@ export declare class SinglyLinkedList<E = any> {
134
232
  */
135
233
  clear(): void;
136
234
  /**
235
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to traverse the entire list to convert it to an array.
236
+ * Space Complexity: O(n) - Linear space, as it creates an array with the same length as the list.
237
+ */
238
+ /**
239
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to traverse the entire list to convert it to an array.
240
+ * Space Complexity: O(n) - Linear space, as it creates an array with the same length as the list.
241
+ *
137
242
  * The `toArray` function converts a linked list into an array.
138
243
  * @returns The `toArray()` method is returning an array of type `E[]`.
139
244
  */
140
245
  toArray(): E[];
141
246
  /**
247
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
248
+ * Space Complexity: O(1) - Constant space.
249
+ */
250
+ /**
251
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
252
+ * Space Complexity: O(1) - Constant space.
253
+ *
142
254
  * The `reverse` function reverses the order of the nodes in a singly linked list.
143
255
  * @returns The reverse() method does not return anything. It has a return type of void.
144
256
  */
145
257
  reverse(): void;
146
258
  /**
259
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
260
+ * Space Complexity: O(1) - Constant space.
261
+ */
262
+ /**
263
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
264
+ * Space Complexity: O(1) - Constant space.
265
+ *
147
266
  * The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
148
267
  * @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
149
268
  * function is used to determine whether a particular value in the linked list satisfies a certain condition.
@@ -152,6 +271,13 @@ export declare class SinglyLinkedList<E = any> {
152
271
  */
153
272
  find(callback: (value: E) => boolean): E | null;
154
273
  /**
274
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
275
+ * Space Complexity: O(1) - Constant space.
276
+ */
277
+ /**
278
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
279
+ * Space Complexity: O(1) - Constant space.
280
+ *
155
281
  * The `indexOf` function returns the index of the first occurrence of a given value in a linked list.
156
282
  * @param {E} value - The value parameter is the value that you want to find the index of in the linked list.
157
283
  * @returns The method is returning the index of the first occurrence of the specified value in the linked list. If the
@@ -159,6 +285,13 @@ export declare class SinglyLinkedList<E = any> {
159
285
  */
160
286
  indexOf(value: E): number;
161
287
  /**
288
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
289
+ * Space Complexity: O(1) - Constant space.
290
+ */
291
+ /**
292
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
293
+ * Space Complexity: O(1) - Constant space.
294
+ *
162
295
  * The function finds a node in a singly linked list by its value and returns the node if found, otherwise returns
163
296
  * null.
164
297
  * @param {E} value - The value parameter is the value that we want to search for in the linked list.
@@ -167,6 +300,13 @@ export declare class SinglyLinkedList<E = any> {
167
300
  */
168
301
  getNode(value: E): SinglyLinkedListNode<E> | null;
169
302
  /**
303
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
304
+ * Space Complexity: O(1) - Constant space.
305
+ */
306
+ /**
307
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
308
+ * Space Complexity: O(1) - Constant space.
309
+ *
170
310
  * The `insertBefore` function inserts a new value before an existing value in a singly linked list.
171
311
  * @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node that you want to insert the
172
312
  * new value before. It can be either the value itself or a node containing the value in the linked list.
@@ -176,6 +316,13 @@ export declare class SinglyLinkedList<E = any> {
176
316
  */
177
317
  insertBefore(existingValueOrNode: E | SinglyLinkedListNode<E>, newValue: E): boolean;
178
318
  /**
319
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
320
+ * Space Complexity: O(1) - Constant space.
321
+ */
322
+ /**
323
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
324
+ * Space Complexity: O(1) - Constant space.
325
+ *
179
326
  * The `insertAfter` function inserts a new node with a given value after an existing node in a singly linked list.
180
327
  * @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node in the linked list after which
181
328
  * the new value will be inserted. It can be either the value of the existing node or the existing node itself.
@@ -185,12 +332,26 @@ export declare class SinglyLinkedList<E = any> {
185
332
  */
186
333
  insertAfter(existingValueOrNode: E | SinglyLinkedListNode<E>, newValue: E): boolean;
187
334
  /**
335
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
336
+ * Space Complexity: O(1) - Constant space.
337
+ */
338
+ /**
339
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
340
+ * Space Complexity: O(1) - Constant space.
341
+ *
188
342
  * The function counts the number of occurrences of a given value in a linked list.
189
343
  * @param {E} value - The value parameter is the value that you want to count the occurrences of in the linked list.
190
344
  * @returns The count of occurrences of the given value in the linked list.
191
345
  */
192
346
  countOccurrences(value: E): number;
193
347
  /**
348
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
349
+ * Space Complexity: O(1) - Constant space.
350
+ */
351
+ /**
352
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
353
+ * Space Complexity: O(1) - Constant space.
354
+ *
194
355
  * The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
195
356
  * @param callback - The callback parameter is a function that takes two arguments: value and index. The value argument
196
357
  * represents the value of the current node in the linked list, and the index argument represents the index of the
@@ -198,6 +359,13 @@ export declare class SinglyLinkedList<E = any> {
198
359
  */
199
360
  forEach(callback: (value: E, index: number) => void): void;
200
361
  /**
362
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as they need to traverse the entire list to apply the callback or reduce the list.
363
+ * Space Complexity: O(n) - Linear space, as they create new nodes or arrays.
364
+ */
365
+ /**
366
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as they need to traverse the entire list to apply the callback or reduce the list.
367
+ * Space Complexity: O(n) - Linear space, as they create new nodes or arrays.
368
+ *
201
369
  * The `map` function takes a callback function and applies it to each element in the SinglyLinkedList, returning a new
202
370
  * SinglyLinkedList with the transformed values.
203
371
  * @param callback - The callback parameter is a function that takes a value of type E (the type of values stored in
@@ -207,6 +375,13 @@ export declare class SinglyLinkedList<E = any> {
207
375
  */
208
376
  map<U>(callback: (value: E) => U): SinglyLinkedList<U>;
209
377
  /**
378
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as they need to traverse the entire list to apply the callback or reduce the list.
379
+ * Space Complexity: O(n) - Linear space, as they create new nodes or arrays.
380
+ */
381
+ /**
382
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as they need to traverse the entire list to apply the callback or reduce the list.
383
+ * Space Complexity: O(n) - Linear space, as they create new nodes or arrays.
384
+ *
210
385
  * The `filter` function iterates through a SinglyLinkedList and returns a new SinglyLinkedList containing only the
211
386
  * elements that satisfy the given callback function.
212
387
  * @param callback - The `callback` parameter is a function that takes a value of type `E` and returns a boolean value.
@@ -215,6 +390,13 @@ export declare class SinglyLinkedList<E = any> {
215
390
  */
216
391
  filter(callback: (value: E) => boolean): SinglyLinkedList<E>;
217
392
  /**
393
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as they need to traverse the entire list to apply the callback or reduce the list.
394
+ * Space Complexity: O(n) - Linear space, as they create new nodes or arrays.
395
+ */
396
+ /**
397
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as they need to traverse the entire list to apply the callback or reduce the list.
398
+ * Space Complexity: O(n) - Linear space, as they create new nodes or arrays.
399
+ *
218
400
  * The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
219
401
  * single value.
220
402
  * @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `value`. It is