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
@@ -55,6 +55,14 @@ export class DoublyLinkedList<E = any> {
55
55
  }
56
56
 
57
57
  /**
58
+ * Time Complexity: O(n), where n is the length of the input array.
59
+ * Space Complexity: O(n)
60
+ */
61
+
62
+ /**
63
+ * Time Complexity: O(n), where n is the length of the input array.
64
+ * Space Complexity: O(n)
65
+ *
58
66
  * The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
59
67
  * given array.
60
68
  * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
@@ -69,6 +77,14 @@ export class DoublyLinkedList<E = any> {
69
77
  }
70
78
 
71
79
  /**
80
+ * Time Complexity: O(1)
81
+ * Space Complexity: O(1)
82
+ */
83
+
84
+ /**
85
+ * Time Complexity: O(1)
86
+ * Space Complexity: O(1)
87
+ *
72
88
  * The push function adds a new node with the given value to the end of the doubly linked list.
73
89
  * @param {E} value - The value to be added to the linked list.
74
90
  */
@@ -86,6 +102,14 @@ export class DoublyLinkedList<E = any> {
86
102
  }
87
103
 
88
104
  /**
105
+ * Time Complexity: O(1)
106
+ * Space Complexity: O(1)
107
+ */
108
+
109
+ /**
110
+ * Time Complexity: O(1)
111
+ * Space Complexity: O(1)
112
+ *
89
113
  * The addLast function adds a new node with the given value to the end of the doubly linked list.
90
114
  * @param {E} value - The value to be added to the linked list.
91
115
  */
@@ -94,6 +118,14 @@ export class DoublyLinkedList<E = any> {
94
118
  }
95
119
 
96
120
  /**
121
+ * Time Complexity: O(1)
122
+ * Space Complexity: O(1)
123
+ */
124
+
125
+ /**
126
+ * Time Complexity: O(1)
127
+ * Space Complexity: O(1)
128
+ *
97
129
  * The `pop()` function removes and returns the value of the last node in a doubly linked list.
98
130
  * @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
99
131
  * list is empty, it returns null.
@@ -113,6 +145,14 @@ export class DoublyLinkedList<E = any> {
113
145
  }
114
146
 
115
147
  /**
148
+ * Time Complexity: O(1)
149
+ * Space Complexity: O(1)
150
+ */
151
+
152
+ /**
153
+ * Time Complexity: O(1)
154
+ * Space Complexity: O(1)
155
+ *
116
156
  * The `popLast()` function removes and returns the value of the last node in a doubly linked list.
117
157
  * @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
118
158
  * list is empty, it returns null.
@@ -122,6 +162,14 @@ export class DoublyLinkedList<E = any> {
122
162
  }
123
163
 
124
164
  /**
165
+ * Time Complexity: O(1)
166
+ * Space Complexity: O(1)
167
+ */
168
+
169
+ /**
170
+ * Time Complexity: O(1)
171
+ * Space Complexity: O(1)
172
+ *
125
173
  * The `shift()` function removes and returns the value of the first node in a doubly linked list.
126
174
  * @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
127
175
  * list.
@@ -141,6 +189,14 @@ export class DoublyLinkedList<E = any> {
141
189
  }
142
190
 
143
191
  /**
192
+ * Time Complexity: O(1)
193
+ * Space Complexity: O(1)
194
+ */
195
+
196
+ /**
197
+ * Time Complexity: O(1)
198
+ * Space Complexity: O(1)
199
+ *
144
200
  * The `popFirst()` function removes and returns the value of the first node in a doubly linked list.
145
201
  * @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
146
202
  * list.
@@ -150,6 +206,14 @@ export class DoublyLinkedList<E = any> {
150
206
  }
151
207
 
152
208
  /**
209
+ * Time Complexity: O(1)
210
+ * Space Complexity: O(1)
211
+ */
212
+
213
+ /**
214
+ * Time Complexity: O(1)
215
+ * Space Complexity: O(1)
216
+ *
153
217
  * The unshift function adds a new node with the given value to the beginning of a doubly linked list.
154
218
  * @param {E} value - The `value` parameter represents the value of the new node that will be added to the beginning of the
155
219
  * doubly linked list.
@@ -168,6 +232,14 @@ export class DoublyLinkedList<E = any> {
168
232
  }
169
233
 
170
234
  /**
235
+ * Time Complexity: O(1)
236
+ * Space Complexity: O(1)
237
+ */
238
+
239
+ /**
240
+ * Time Complexity: O(1)
241
+ * Space Complexity: O(1)
242
+ *
171
243
  * The addFirst function adds a new node with the given value to the beginning of a doubly linked list.
172
244
  * @param {E} value - The `value` parameter represents the value of the new node that will be added to the beginning of the
173
245
  * doubly linked list.
@@ -177,6 +249,14 @@ export class DoublyLinkedList<E = any> {
177
249
  }
178
250
 
179
251
  /**
252
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
253
+ * Space Complexity: O(1)
254
+ */
255
+
256
+ /**
257
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
258
+ * Space Complexity: O(1)
259
+ *
180
260
  * The `getFirst` function returns the first node in a doubly linked list, or null if the list is empty.
181
261
  * @returns The method `getFirst()` returns the first node of the doubly linked list, or `null` if the list is empty.
182
262
  */
@@ -185,6 +265,14 @@ export class DoublyLinkedList<E = any> {
185
265
  }
186
266
 
187
267
  /**
268
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
269
+ * Space Complexity: O(1)
270
+ */
271
+
272
+ /**
273
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
274
+ * Space Complexity: O(1)
275
+ *
188
276
  * The `getLast` function returns the last node in a doubly linked list, or null if the list is empty.
189
277
  * @returns The method `getLast()` returns the last node of the doubly linked list, or `null` if the list is empty.
190
278
  */
@@ -193,6 +281,14 @@ export class DoublyLinkedList<E = any> {
193
281
  }
194
282
 
195
283
  /**
284
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
285
+ * Space Complexity: O(1)
286
+ */
287
+
288
+ /**
289
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
290
+ * Space Complexity: O(1)
291
+ *
196
292
  * The `getAt` function returns the value at a specified index in a linked list, or null if the index is out of bounds.
197
293
  * @param {number} index - The index parameter is a number that represents the position of the element we want to
198
294
  * retrieve from the list.
@@ -209,6 +305,14 @@ export class DoublyLinkedList<E = any> {
209
305
  }
210
306
 
211
307
  /**
308
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
309
+ * Space Complexity: O(1)
310
+ */
311
+
312
+ /**
313
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
314
+ * Space Complexity: O(1)
315
+ *
212
316
  * The function `getNodeAt` returns the node at a given index in a doubly linked list, or null if the index is out of
213
317
  * range.
214
318
  * @param {number} index - The `index` parameter is a number that represents the position of the node we want to
@@ -226,6 +330,14 @@ export class DoublyLinkedList<E = any> {
226
330
  }
227
331
 
228
332
  /**
333
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
334
+ * Space Complexity: O(1)
335
+ */
336
+
337
+ /**
338
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
339
+ * Space Complexity: O(1)
340
+ *
229
341
  * The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
230
342
  * node if found, otherwise it returns null.
231
343
  * @param {E} value - The `value` parameter is the value that we want to search for in the doubly linked list.
@@ -246,6 +358,14 @@ export class DoublyLinkedList<E = any> {
246
358
  }
247
359
 
248
360
  /**
361
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
362
+ * Space Complexity: O(1)
363
+ */
364
+
365
+ /**
366
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
367
+ * Space Complexity: O(1)
368
+ *
249
369
  * The `insert` function inserts a value at a specified index in a doubly linked list.
250
370
  * @param {number} index - The index parameter represents the position at which the new value should be inserted in the
251
371
  * DoublyLinkedList. It is of type number.
@@ -277,6 +397,14 @@ export class DoublyLinkedList<E = any> {
277
397
  }
278
398
 
279
399
  /**
400
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
401
+ * Space Complexity: O(1)
402
+ */
403
+
404
+ /**
405
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
406
+ * Space Complexity: O(1)
407
+ *
280
408
  * The `insertBefore` function inserts a new value before an existing value or node in a doubly linked list.
281
409
  * @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
282
410
  * before which the new value will be inserted. It can be either the value of the existing node or the existing node
@@ -314,6 +442,14 @@ export class DoublyLinkedList<E = any> {
314
442
  }
315
443
 
316
444
  /**
445
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
446
+ * Space Complexity: O(1)
447
+ */
448
+
449
+ /**
450
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
451
+ * Space Complexity: O(1)
452
+ *
317
453
  * The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
318
454
  * @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
319
455
  * data structure. It is of type number.
@@ -335,6 +471,14 @@ export class DoublyLinkedList<E = any> {
335
471
  }
336
472
 
337
473
  /**
474
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
475
+ * Space Complexity: O(1)
476
+ */
477
+
478
+ /**
479
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
480
+ * Space Complexity: O(1)
481
+ *
338
482
  * The `delete` function removes a node from a doubly linked list based on either the node itself or its value.
339
483
  * @param {E | DoublyLinkedListNode<E>} valOrNode - The `valOrNode` parameter can accept either a value of type `E` or
340
484
  * a `DoublyLinkedListNode<E>` object.
@@ -368,6 +512,14 @@ export class DoublyLinkedList<E = any> {
368
512
  }
369
513
 
370
514
  /**
515
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
516
+ * Space Complexity: O(n)
517
+ */
518
+
519
+ /**
520
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
521
+ * Space Complexity: O(n)
522
+ *
371
523
  * The `toArray` function converts a linked list into an array.
372
524
  * @returns The `toArray()` method is returning an array of type `E[]`.
373
525
  */
@@ -399,6 +551,14 @@ export class DoublyLinkedList<E = any> {
399
551
  }
400
552
 
401
553
  /**
554
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
555
+ * Space Complexity: O(1)
556
+ */
557
+
558
+ /**
559
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
560
+ * Space Complexity: O(1)
561
+ *
402
562
  * The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
403
563
  * @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
404
564
  * function is used to determine whether a particular value in the linked list satisfies a certain condition.
@@ -417,6 +577,14 @@ export class DoublyLinkedList<E = any> {
417
577
  }
418
578
 
419
579
  /**
580
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
581
+ * Space Complexity: O(1)
582
+ */
583
+
584
+ /**
585
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
586
+ * Space Complexity: O(1)
587
+ *
420
588
  * The function returns the index of the first occurrence of a given value in a linked list.
421
589
  * @param {E} value - The parameter `value` is of type `E`, which means it can be any data type. It represents the value
422
590
  * that we are searching for in the linked list.
@@ -437,6 +605,14 @@ export class DoublyLinkedList<E = any> {
437
605
  }
438
606
 
439
607
  /**
608
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
609
+ * Space Complexity: O(1)
610
+ */
611
+
612
+ /**
613
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
614
+ * Space Complexity: O(1)
615
+ *
440
616
  * The `findBackward` function iterates through a linked list from the last node to the first node and returns the last
441
617
  * value that satisfies the given callback function, or null if no value satisfies the callback.
442
618
  * @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
@@ -456,6 +632,14 @@ export class DoublyLinkedList<E = any> {
456
632
  }
457
633
 
458
634
  /**
635
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
636
+ * Space Complexity: O(n)
637
+ */
638
+
639
+ /**
640
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
641
+ * Space Complexity: O(n)
642
+ *
459
643
  * The `toArrayBackward` function converts a doubly linked list into an array in reverse order.
460
644
  * @returns The `toArrayBackward()` function returns an array of type `E[]`.
461
645
  */
@@ -470,6 +654,14 @@ export class DoublyLinkedList<E = any> {
470
654
  }
471
655
 
472
656
  /**
657
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
658
+ * Space Complexity: O(1)
659
+ */
660
+
661
+ /**
662
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
663
+ * Space Complexity: O(1)
664
+ *
473
665
  * The `reverse` function reverses the order of the elements in a doubly linked list.
474
666
  */
475
667
  reverse(): void {
@@ -483,6 +675,14 @@ export class DoublyLinkedList<E = any> {
483
675
  }
484
676
 
485
677
  /**
678
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
679
+ * Space Complexity: O(1)
680
+ */
681
+
682
+ /**
683
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
684
+ * Space Complexity: O(1)
685
+ *
486
686
  * The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
487
687
  * @param callback - The callback parameter is a function that takes two arguments: value and index. The value argument
488
688
  * represents the value of the current node in the linked list, and the index argument represents the index of the
@@ -499,6 +699,14 @@ export class DoublyLinkedList<E = any> {
499
699
  }
500
700
 
501
701
  /**
702
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
703
+ * Space Complexity: O(n)
704
+ */
705
+
706
+ /**
707
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
708
+ * Space Complexity: O(n)
709
+ *
502
710
  * The `map` function takes a callback function and applies it to each element in the DoublyLinkedList, returning a new
503
711
  * DoublyLinkedList with the transformed values.
504
712
  * @param callback - The callback parameter is a function that takes a value of type E (the type of values stored in
@@ -517,6 +725,14 @@ export class DoublyLinkedList<E = any> {
517
725
  }
518
726
 
519
727
  /**
728
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
729
+ * Space Complexity: O(n)
730
+ */
731
+
732
+ /**
733
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
734
+ * Space Complexity: O(n)
735
+ *
520
736
  * The `filter` function iterates through a DoublyLinkedList and returns a new DoublyLinkedList containing only the
521
737
  * elements that satisfy the given callback function.
522
738
  * @param callback - The `callback` parameter is a function that takes a value of type `E` and returns a boolean value.
@@ -536,6 +752,14 @@ export class DoublyLinkedList<E = any> {
536
752
  }
537
753
 
538
754
  /**
755
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
756
+ * Space Complexity: O(n)
757
+ */
758
+
759
+ /**
760
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
761
+ * Space Complexity: O(n)
762
+ *
539
763
  * The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
540
764
  * single value.
541
765
  * @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `value`. It is
@@ -556,6 +780,14 @@ export class DoublyLinkedList<E = any> {
556
780
  }
557
781
 
558
782
  /**
783
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
784
+ * Space Complexity: O(1)
785
+ */
786
+
787
+ /**
788
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
789
+ * Space Complexity: O(1)
790
+ *
559
791
  * The `insertAfter` function inserts a new node with a given value after an existing node in a doubly linked list.
560
792
  * @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
561
793
  * after which the new value will be inserted. It can be either the value of the existing node or the existing node