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
@@ -49,6 +49,14 @@ export class SinglyLinkedList<E = any> {
49
49
  }
50
50
 
51
51
  /**
52
+ * 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.
53
+ * Space Complexity: O(n) - Linear space, as it creates a new node for each element in the array.
54
+ */
55
+
56
+ /**
57
+ * 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.
58
+ * Space Complexity: O(n) - Linear space, as it creates a new node for each element in the array.
59
+ *
52
60
  * The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
53
61
  * array.
54
62
  * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
@@ -63,6 +71,14 @@ export class SinglyLinkedList<E = any> {
63
71
  }
64
72
 
65
73
  /**
74
+ * Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
75
+ * Space Complexity: O(1) - Constant space, as it only creates a new node.
76
+ */
77
+
78
+ /**
79
+ * Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
80
+ * Space Complexity: O(1) - Constant space, as it only creates a new node.
81
+ *
66
82
  * The `push` function adds a new node with the given value to the end of a singly linked list.
67
83
  * @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
68
84
  * any type (E) as specified in the generic type declaration of the class or function.
@@ -80,6 +96,14 @@ export class SinglyLinkedList<E = any> {
80
96
  }
81
97
 
82
98
  /**
99
+ * Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
100
+ * Space Complexity: O(1) - Constant space, as it only creates a new node.
101
+ */
102
+
103
+ /**
104
+ * Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
105
+ * Space Complexity: O(1) - Constant space, as it only creates a new node.
106
+ *
83
107
  * The `push` function adds a new node with the given value to the end of a singly linked list.
84
108
  * @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
85
109
  * any type (E) as specified in the generic type declaration of the class or function.
@@ -89,6 +113,14 @@ export class SinglyLinkedList<E = any> {
89
113
  }
90
114
 
91
115
  /**
116
+ * Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
117
+ * Space Complexity: O(1) - Constant space.
118
+ */
119
+
120
+ /**
121
+ * Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
122
+ * Space Complexity: O(1) - Constant space.
123
+ *
92
124
  * The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail
93
125
  * pointers accordingly.
94
126
  * @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
@@ -116,6 +148,14 @@ export class SinglyLinkedList<E = any> {
116
148
  }
117
149
 
118
150
  /**
151
+ * Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
152
+ * Space Complexity: O(1) - Constant space.
153
+ */
154
+
155
+ /**
156
+ * Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
157
+ * Space Complexity: O(1) - Constant space.
158
+ *
119
159
  * The `popLast()` function removes and returns the value of the last element in a linked list, updating the head and tail
120
160
  * pointers accordingly.
121
161
  * @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
@@ -126,6 +166,14 @@ export class SinglyLinkedList<E = any> {
126
166
  }
127
167
 
128
168
  /**
169
+ * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
170
+ * Space Complexity: O(1) - Constant space.
171
+ */
172
+
173
+ /**
174
+ * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
175
+ * Space Complexity: O(1) - Constant space.
176
+ *
129
177
  * The `shift()` function removes and returns the value of the first node in a linked list.
130
178
  * @returns The value of the node that is being removed from the beginning of the linked list.
131
179
  */
@@ -138,6 +186,14 @@ export class SinglyLinkedList<E = any> {
138
186
  }
139
187
 
140
188
  /**
189
+ * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
190
+ * Space Complexity: O(1) - Constant space.
191
+ */
192
+
193
+ /**
194
+ * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
195
+ * Space Complexity: O(1) - Constant space.
196
+ *
141
197
  * The `popFirst()` function removes and returns the value of the first node in a linked list.
142
198
  * @returns The value of the node that is being removed from the beginning of the linked list.
143
199
  */
@@ -146,6 +202,14 @@ export class SinglyLinkedList<E = any> {
146
202
  }
147
203
 
148
204
  /**
205
+ * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
206
+ * Space Complexity: O(1) - Constant space.
207
+ */
208
+
209
+ /**
210
+ * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
211
+ * Space Complexity: O(1) - Constant space.
212
+ *
149
213
  * The unshift function adds a new node with the given value to the beginning of a singly linked list.
150
214
  * @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
151
215
  * linked list.
@@ -163,6 +227,14 @@ export class SinglyLinkedList<E = any> {
163
227
  }
164
228
 
165
229
  /**
230
+ * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
231
+ * Space Complexity: O(1) - Constant space.
232
+ */
233
+
234
+ /**
235
+ * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
236
+ * Space Complexity: O(1) - Constant space.
237
+ *
166
238
  * The addFirst function adds a new node with the given value to the beginning of a singly linked list.
167
239
  * @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
168
240
  * linked list.
@@ -172,6 +244,14 @@ export class SinglyLinkedList<E = any> {
172
244
  }
173
245
 
174
246
  /**
247
+ * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
248
+ * Space Complexity: O(1) - Constant space.
249
+ */
250
+
251
+ /**
252
+ * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
253
+ * Space Complexity: O(1) - Constant space.
254
+ *
175
255
  * The function `getAt` returns the value at a specified index in a linked list, or null if the index is out of range.
176
256
  * @param {number} index - The index parameter is a number that represents the position of the element we want to
177
257
  * retrieve from the list.
@@ -188,6 +268,14 @@ export class SinglyLinkedList<E = any> {
188
268
  }
189
269
 
190
270
  /**
271
+ * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
272
+ * Space Complexity: O(1) - Constant space.
273
+ */
274
+
275
+ /**
276
+ * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
277
+ * Space Complexity: O(1) - Constant space.
278
+ *
191
279
  * The function `getNodeAt` returns the node at a given index in a singly linked list.
192
280
  * @param {number} index - The `index` parameter is a number that represents the position of the node we want to
193
281
  * retrieve from the linked list. It indicates the zero-based index of the node we want to access.
@@ -203,6 +291,14 @@ export class SinglyLinkedList<E = any> {
203
291
  }
204
292
 
205
293
  /**
294
+ * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
295
+ * Space Complexity: O(1) - Constant space.
296
+ */
297
+
298
+ /**
299
+ * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
300
+ * Space Complexity: O(1) - Constant space.
301
+ *
206
302
  * The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
207
303
  * @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
208
304
  * data structure. It is of type number.
@@ -222,6 +318,14 @@ export class SinglyLinkedList<E = any> {
222
318
  }
223
319
 
224
320
  /**
321
+ * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
322
+ * Space Complexity: O(1) - Constant space.
323
+ */
324
+
325
+ /**
326
+ * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
327
+ * Space Complexity: O(1) - Constant space.
328
+ *
225
329
  * The delete function removes a node with a specific value from a singly linked list.
226
330
  * @param {E | SinglyLinkedListNode<E>} valueOrNode - The `valueOrNode` parameter can accept either a value of type `E`
227
331
  * or a `SinglyLinkedListNode<E>` object.
@@ -263,6 +367,14 @@ export class SinglyLinkedList<E = any> {
263
367
  }
264
368
 
265
369
  /**
370
+ * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
371
+ * Space Complexity: O(1) - Constant space.
372
+ */
373
+
374
+ /**
375
+ * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
376
+ * Space Complexity: O(1) - Constant space.
377
+ *
266
378
  * The `insertAt` function inserts a value at a specified index in a singly linked list.
267
379
  * @param {number} index - The index parameter represents the position at which the new value should be inserted in the
268
380
  * linked list. It is of type number.
@@ -309,6 +421,14 @@ export class SinglyLinkedList<E = any> {
309
421
  }
310
422
 
311
423
  /**
424
+ * 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.
425
+ * Space Complexity: O(n) - Linear space, as it creates an array with the same length as the list.
426
+ */
427
+
428
+ /**
429
+ * 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.
430
+ * Space Complexity: O(n) - Linear space, as it creates an array with the same length as the list.
431
+ *
312
432
  * The `toArray` function converts a linked list into an array.
313
433
  * @returns The `toArray()` method is returning an array of type `E[]`.
314
434
  */
@@ -323,6 +443,14 @@ export class SinglyLinkedList<E = any> {
323
443
  }
324
444
 
325
445
  /**
446
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
447
+ * Space Complexity: O(1) - Constant space.
448
+ */
449
+
450
+ /**
451
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
452
+ * Space Complexity: O(1) - Constant space.
453
+ *
326
454
  * The `reverse` function reverses the order of the nodes in a singly linked list.
327
455
  * @returns The reverse() method does not return anything. It has a return type of void.
328
456
  */
@@ -344,6 +472,14 @@ export class SinglyLinkedList<E = any> {
344
472
  }
345
473
 
346
474
  /**
475
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
476
+ * Space Complexity: O(1) - Constant space.
477
+ */
478
+
479
+ /**
480
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
481
+ * Space Complexity: O(1) - Constant space.
482
+ *
347
483
  * The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
348
484
  * @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
349
485
  * function is used to determine whether a particular value in the linked list satisfies a certain condition.
@@ -362,6 +498,14 @@ export class SinglyLinkedList<E = any> {
362
498
  }
363
499
 
364
500
  /**
501
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
502
+ * Space Complexity: O(1) - Constant space.
503
+ */
504
+
505
+ /**
506
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
507
+ * Space Complexity: O(1) - Constant space.
508
+ *
365
509
  * The `indexOf` function returns the index of the first occurrence of a given value in a linked list.
366
510
  * @param {E} value - The value parameter is the value that you want to find the index of in the linked list.
367
511
  * @returns The method is returning the index of the first occurrence of the specified value in the linked list. If the
@@ -383,6 +527,14 @@ export class SinglyLinkedList<E = any> {
383
527
  }
384
528
 
385
529
  /**
530
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
531
+ * Space Complexity: O(1) - Constant space.
532
+ */
533
+
534
+ /**
535
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
536
+ * Space Complexity: O(1) - Constant space.
537
+ *
386
538
  * The function finds a node in a singly linked list by its value and returns the node if found, otherwise returns
387
539
  * null.
388
540
  * @param {E} value - The value parameter is the value that we want to search for in the linked list.
@@ -403,6 +555,14 @@ export class SinglyLinkedList<E = any> {
403
555
  }
404
556
 
405
557
  /**
558
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
559
+ * Space Complexity: O(1) - Constant space.
560
+ */
561
+
562
+ /**
563
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
564
+ * Space Complexity: O(1) - Constant space.
565
+ *
406
566
  * The `insertBefore` function inserts a new value before an existing value in a singly linked list.
407
567
  * @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node that you want to insert the
408
568
  * new value before. It can be either the value itself or a node containing the value in the linked list.
@@ -440,6 +600,14 @@ export class SinglyLinkedList<E = any> {
440
600
  }
441
601
 
442
602
  /**
603
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
604
+ * Space Complexity: O(1) - Constant space.
605
+ */
606
+
607
+ /**
608
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
609
+ * Space Complexity: O(1) - Constant space.
610
+ *
443
611
  * The `insertAfter` function inserts a new node with a given value after an existing node in a singly linked list.
444
612
  * @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node in the linked list after which
445
613
  * the new value will be inserted. It can be either the value of the existing node or the existing node itself.
@@ -471,6 +639,14 @@ export class SinglyLinkedList<E = any> {
471
639
  }
472
640
 
473
641
  /**
642
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
643
+ * Space Complexity: O(1) - Constant space.
644
+ */
645
+
646
+ /**
647
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
648
+ * Space Complexity: O(1) - Constant space.
649
+ *
474
650
  * The function counts the number of occurrences of a given value in a linked list.
475
651
  * @param {E} value - The value parameter is the value that you want to count the occurrences of in the linked list.
476
652
  * @returns The count of occurrences of the given value in the linked list.
@@ -490,6 +666,14 @@ export class SinglyLinkedList<E = any> {
490
666
  }
491
667
 
492
668
  /**
669
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
670
+ * Space Complexity: O(1) - Constant space.
671
+ */
672
+
673
+ /**
674
+ * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
675
+ * Space Complexity: O(1) - Constant space.
676
+ *
493
677
  * The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
494
678
  * @param callback - The callback parameter is a function that takes two arguments: value and index. The value argument
495
679
  * represents the value of the current node in the linked list, and the index argument represents the index of the
@@ -506,6 +690,14 @@ export class SinglyLinkedList<E = any> {
506
690
  }
507
691
 
508
692
  /**
693
+ * 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.
694
+ * Space Complexity: O(n) - Linear space, as they create new nodes or arrays.
695
+ */
696
+
697
+ /**
698
+ * 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.
699
+ * Space Complexity: O(n) - Linear space, as they create new nodes or arrays.
700
+ *
509
701
  * The `map` function takes a callback function and applies it to each element in the SinglyLinkedList, returning a new
510
702
  * SinglyLinkedList with the transformed values.
511
703
  * @param callback - The callback parameter is a function that takes a value of type E (the type of values stored in
@@ -524,6 +716,14 @@ export class SinglyLinkedList<E = any> {
524
716
  }
525
717
 
526
718
  /**
719
+ * 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.
720
+ * Space Complexity: O(n) - Linear space, as they create new nodes or arrays.
721
+ */
722
+
723
+ /**
724
+ * 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.
725
+ * Space Complexity: O(n) - Linear space, as they create new nodes or arrays.
726
+ *
527
727
  * The `filter` function iterates through a SinglyLinkedList and returns a new SinglyLinkedList containing only the
528
728
  * elements that satisfy the given callback function.
529
729
  * @param callback - The `callback` parameter is a function that takes a value of type `E` and returns a boolean value.
@@ -543,6 +743,14 @@ export class SinglyLinkedList<E = any> {
543
743
  }
544
744
 
545
745
  /**
746
+ * 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.
747
+ * Space Complexity: O(n) - Linear space, as they create new nodes or arrays.
748
+ */
749
+
750
+ /**
751
+ * 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.
752
+ * Space Complexity: O(n) - Linear space, as they create new nodes or arrays.
753
+ *
546
754
  * The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
547
755
  * single value.
548
756
  * @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `value`. It is
@@ -58,6 +58,14 @@ export class SkipList<K, V> {
58
58
  }
59
59
 
60
60
  /**
61
+ * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
62
+ * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
63
+ */
64
+
65
+ /**
66
+ * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
67
+ * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
68
+ *
61
69
  * The add function adds a new node with a given key and value to a Skip List data structure.
62
70
  * @param {K} key - The key parameter represents the key of the node that needs to be added to the skip list.
63
71
  * @param {V} value - The "value" parameter represents the value associated with the key that is being added to the Skip
@@ -86,6 +94,14 @@ export class SkipList<K, V> {
86
94
  }
87
95
 
88
96
  /**
97
+ * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
98
+ * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
99
+ */
100
+
101
+ /**
102
+ * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
103
+ * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
104
+ *
89
105
  * The function `get` retrieves the value associated with a given key from a skip list data structure.
90
106
  * @param {K} key - The `key` parameter is the key of the element that we want to retrieve from the data structure.
91
107
  * @returns The method `get(key: K)` returns the value associated with the given key if it exists in the data structure,
@@ -108,11 +124,29 @@ export class SkipList<K, V> {
108
124
  return undefined;
109
125
  }
110
126
 
127
+ /**
128
+ * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
129
+ * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
130
+ */
131
+
132
+ /**
133
+ * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
134
+ * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
135
+ */
136
+
111
137
  has(key: K): boolean {
112
138
  return this.get(key) !== undefined;
113
139
  }
114
140
 
115
141
  /**
142
+ * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
143
+ * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
144
+ */
145
+
146
+ /**
147
+ * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
148
+ * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
149
+ *
116
150
  * The `delete` function removes a node with a specific key from a Skip List data structure.
117
151
  * @param {K} key - The key parameter represents the key of the node that needs to be removed from the skip list.
118
152
  * @returns The `delete` method returns a boolean value. It returns `true` if the key was successfully removed from the
@@ -148,6 +182,14 @@ export class SkipList<K, V> {
148
182
  }
149
183
 
150
184
  /**
185
+ * Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
186
+ * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
187
+ */
188
+
189
+ /**
190
+ * Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
191
+ * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
192
+ *
151
193
  * Get the value of the first element (the smallest element) in the Skip List.
152
194
  * @returns The value of the first element, or undefined if the Skip List is empty.
153
195
  */
@@ -157,6 +199,14 @@ export class SkipList<K, V> {
157
199
  }
158
200
 
159
201
  /**
202
+ * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
203
+ * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
204
+ */
205
+
206
+ /**
207
+ * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
208
+ * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
209
+ *
160
210
  * Get the value of the last element (the largest element) in the Skip List.
161
211
  * @returns The value of the last element, or undefined if the Skip List is empty.
162
212
  */
@@ -171,6 +221,14 @@ export class SkipList<K, V> {
171
221
  }
172
222
 
173
223
  /**
224
+ * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
225
+ * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
226
+ */
227
+
228
+ /**
229
+ * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
230
+ * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
231
+ *
174
232
  * Get the value of the first element in the Skip List that is greater than the given key.
175
233
  * @param key - the given key.
176
234
  * @returns The value of the first element greater than the given key, or undefined if there is no such element.
@@ -187,6 +245,14 @@ export class SkipList<K, V> {
187
245
  }
188
246
 
189
247
  /**
248
+ * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
249
+ * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
250
+ */
251
+
252
+ /**
253
+ * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
254
+ * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
255
+ *
190
256
  * Get the value of the last element in the Skip List that is less than the given key.
191
257
  * @param key - the given key.
192
258
  * @returns The value of the last element less than the given key, or undefined if there is no such element.
@@ -208,6 +274,14 @@ export class SkipList<K, V> {
208
274
  }
209
275
 
210
276
  /**
277
+ * Time Complexity: O(maxLevel) - where maxLevel is the maximum level of the SkipList, as it may iterate up to maxLevel times in the worst case.
278
+ * Space Complexity: O(1) - constant space.
279
+ */
280
+
281
+ /**
282
+ * Time Complexity: O(maxLevel) - where maxLevel is the maximum level of the SkipList, as it may iterate up to maxLevel times in the worst case.
283
+ * Space Complexity: O(1) - constant space.
284
+ *
211
285
  * The function "_randomLevel" generates a random level based on a given probability and maximum level.
212
286
  * @returns the level, which is a number.
213
287
  */