min-heap-typed 1.42.7 → 1.42.9
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.
- package/dist/data-structures/binary-tree/avl-tree.d.ts +88 -23
- package/dist/data-structures/binary-tree/avl-tree.js +88 -23
- package/dist/data-structures/binary-tree/binary-tree.d.ts +180 -74
- package/dist/data-structures/binary-tree/binary-tree.js +388 -201
- package/dist/data-structures/binary-tree/bst.d.ts +121 -66
- package/dist/data-structures/binary-tree/bst.js +121 -67
- package/dist/data-structures/binary-tree/rb-tree.d.ts +72 -5
- package/dist/data-structures/binary-tree/rb-tree.js +95 -18
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +82 -43
- package/dist/data-structures/binary-tree/tree-multimap.js +82 -43
- package/dist/data-structures/graph/abstract-graph.d.ts +139 -36
- package/dist/data-structures/graph/abstract-graph.js +147 -36
- package/dist/data-structures/graph/directed-graph.d.ts +126 -0
- package/dist/data-structures/graph/directed-graph.js +126 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +63 -0
- package/dist/data-structures/graph/undirected-graph.js +63 -0
- package/dist/data-structures/heap/heap.d.ts +175 -12
- package/dist/data-structures/heap/heap.js +175 -12
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +203 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js +203 -0
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +182 -0
- package/dist/data-structures/linked-list/singly-linked-list.js +182 -0
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +64 -0
- package/dist/data-structures/linked-list/skip-linked-list.js +64 -0
- package/dist/data-structures/queue/deque.d.ts +113 -3
- package/dist/data-structures/queue/deque.js +113 -3
- package/dist/data-structures/queue/queue.d.ts +87 -0
- package/dist/data-structures/queue/queue.js +87 -0
- package/dist/data-structures/stack/stack.d.ts +42 -0
- package/dist/data-structures/stack/stack.js +42 -0
- package/dist/data-structures/trie/trie.d.ts +76 -0
- package/dist/data-structures/trie/trie.js +76 -1
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +97 -23
- package/src/data-structures/binary-tree/binary-tree.ts +419 -204
- package/src/data-structures/binary-tree/bst.ts +130 -68
- package/src/data-structures/binary-tree/rb-tree.ts +106 -19
- package/src/data-structures/binary-tree/tree-multimap.ts +88 -44
- package/src/data-structures/graph/abstract-graph.ts +133 -7
- package/src/data-structures/graph/directed-graph.ts +145 -1
- package/src/data-structures/graph/undirected-graph.ts +72 -0
- package/src/data-structures/heap/heap.ts +201 -12
- package/src/data-structures/linked-list/doubly-linked-list.ts +232 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +208 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +74 -0
- package/src/data-structures/queue/deque.ts +127 -3
- package/src/data-structures/queue/queue.ts +99 -0
- package/src/data-structures/stack/stack.ts +48 -0
- package/src/data-structures/trie/trie.ts +87 -4
|
@@ -53,6 +53,14 @@ export class Heap<E = any> {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
|
+
* Time Complexity: O(log n), where n is the number of nodes in the heap.
|
|
57
|
+
* Space Complexity: O(1)
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Time Complexity: O(log n), where n is the number of nodes in the heap.
|
|
62
|
+
* Space Complexity: O(1)
|
|
63
|
+
*
|
|
56
64
|
* Insert an element into the heap and maintain the heap properties.
|
|
57
65
|
* @param element - The element to be inserted.
|
|
58
66
|
*/
|
|
@@ -61,6 +69,14 @@ export class Heap<E = any> {
|
|
|
61
69
|
}
|
|
62
70
|
|
|
63
71
|
/**
|
|
72
|
+
* Time Complexity: O(log n), where n is the number of nodes in the heap.
|
|
73
|
+
* Space Complexity: O(1)
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Time Complexity: O(log n), where n is the number of nodes in the heap.
|
|
78
|
+
* Space Complexity: O(1)
|
|
79
|
+
*
|
|
64
80
|
* Insert an element into the heap and maintain the heap properties.
|
|
65
81
|
* @param element - The element to be inserted.
|
|
66
82
|
*/
|
|
@@ -71,6 +87,14 @@ export class Heap<E = any> {
|
|
|
71
87
|
}
|
|
72
88
|
|
|
73
89
|
/**
|
|
90
|
+
* Time Complexity: O(log n), where n is the number of nodes in the heap.
|
|
91
|
+
* Space Complexity: O(1)
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Time Complexity: O(log n), where n is the number of nodes in the heap.
|
|
96
|
+
* Space Complexity: O(1)
|
|
97
|
+
*
|
|
74
98
|
* Remove and return the top element (smallest or largest element) from the heap.
|
|
75
99
|
* @returns The top element or undefined if the heap is empty.
|
|
76
100
|
*/
|
|
@@ -89,6 +113,14 @@ export class Heap<E = any> {
|
|
|
89
113
|
}
|
|
90
114
|
|
|
91
115
|
/**
|
|
116
|
+
* Time Complexity: O(log n), where n is the number of nodes in the heap.
|
|
117
|
+
* Space Complexity: O(1)
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Time Complexity: O(log n), where n is the number of nodes in the heap.
|
|
122
|
+
* Space Complexity: O(1)
|
|
123
|
+
*
|
|
92
124
|
* Remove and return the top element (smallest or largest element) from the heap.
|
|
93
125
|
* @returns The top element or undefined if the heap is empty.
|
|
94
126
|
*/
|
|
@@ -123,6 +155,14 @@ export class Heap<E = any> {
|
|
|
123
155
|
}
|
|
124
156
|
|
|
125
157
|
/**
|
|
158
|
+
* Time Complexity: O(n), where n is the number of elements in the nodes array.
|
|
159
|
+
* Space Complexity: O(n)
|
|
160
|
+
*/
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Time Complexity: O(n), where n is the number of elements in the nodes array.
|
|
164
|
+
* Space Complexity: O(n)
|
|
165
|
+
*
|
|
126
166
|
* Clear and add nodes of the heap
|
|
127
167
|
* @param nodes
|
|
128
168
|
*/
|
|
@@ -132,6 +172,14 @@ export class Heap<E = any> {
|
|
|
132
172
|
}
|
|
133
173
|
|
|
134
174
|
/**
|
|
175
|
+
* Time Complexity: O(n), where n is the number of nodes in the heap.
|
|
176
|
+
* Space Complexity: O(1)
|
|
177
|
+
*/
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Time Complexity: O(n), where n is the number of nodes in the heap.
|
|
181
|
+
* Space Complexity: O(1)
|
|
182
|
+
*
|
|
135
183
|
* Use a comparison function to check whether a binary heap contains a specific element.
|
|
136
184
|
* @param element - the element to check.
|
|
137
185
|
* @returns Returns true if the specified element is contained; otherwise, returns false.
|
|
@@ -141,6 +189,14 @@ export class Heap<E = any> {
|
|
|
141
189
|
}
|
|
142
190
|
|
|
143
191
|
/**
|
|
192
|
+
* Time Complexity: O(n), where n is the number of nodes in the heap.
|
|
193
|
+
* Space Complexity: O(h), where h is the height of the heap.
|
|
194
|
+
*/
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Time Complexity: O(n), where n is the number of nodes in the heap.
|
|
198
|
+
* Space Complexity: O(h), where h is the height of the heap.
|
|
199
|
+
*
|
|
144
200
|
* Depth-first search (DFS) method, different traversal orders can be selected。
|
|
145
201
|
* @param order - Traverse order parameter: 'in' (in-order), 'pre' (pre-order) or 'post' (post-order).
|
|
146
202
|
* @returns An array containing elements traversed in the specified order.
|
|
@@ -173,6 +229,14 @@ export class Heap<E = any> {
|
|
|
173
229
|
}
|
|
174
230
|
|
|
175
231
|
/**
|
|
232
|
+
* Time Complexity: O(n)
|
|
233
|
+
* Space Complexity: O(n)
|
|
234
|
+
*/
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Time Complexity: O(n)
|
|
238
|
+
* Space Complexity: O(n)
|
|
239
|
+
*
|
|
176
240
|
* Convert the heap to an array.
|
|
177
241
|
* @returns An array containing the elements of the heap.
|
|
178
242
|
*/
|
|
@@ -180,11 +244,23 @@ export class Heap<E = any> {
|
|
|
180
244
|
return [...this.nodes];
|
|
181
245
|
}
|
|
182
246
|
|
|
247
|
+
/**
|
|
248
|
+
* Time Complexity: O(1)
|
|
249
|
+
* Space Complexity: O(1)
|
|
250
|
+
*/
|
|
183
251
|
getNodes(): E[] {
|
|
184
252
|
return this.nodes;
|
|
185
253
|
}
|
|
186
254
|
|
|
187
255
|
/**
|
|
256
|
+
* Time Complexity: O(n)
|
|
257
|
+
* Space Complexity: O(n)
|
|
258
|
+
*/
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Time Complexity: O(n)
|
|
262
|
+
* Space Complexity: O(n)
|
|
263
|
+
*
|
|
188
264
|
* Clone the heap, creating a new heap with the same elements.
|
|
189
265
|
* @returns A new Heap instance containing the same elements.
|
|
190
266
|
*/
|
|
@@ -195,6 +271,14 @@ export class Heap<E = any> {
|
|
|
195
271
|
}
|
|
196
272
|
|
|
197
273
|
/**
|
|
274
|
+
* Time Complexity: O(n log n)
|
|
275
|
+
* Space Complexity: O(n)
|
|
276
|
+
*/
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Time Complexity: O(n log n)
|
|
280
|
+
* Space Complexity: O(n)
|
|
281
|
+
*
|
|
198
282
|
* Sort the elements in the heap and return them as an array.
|
|
199
283
|
* @returns An array containing the elements sorted in ascending order.
|
|
200
284
|
*/
|
|
@@ -209,6 +293,14 @@ export class Heap<E = any> {
|
|
|
209
293
|
}
|
|
210
294
|
|
|
211
295
|
/**
|
|
296
|
+
* Time Complexity: O(log n)
|
|
297
|
+
* Space Complexity: O(1)
|
|
298
|
+
*/
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Time Complexity: O(log n)
|
|
302
|
+
* Space Complexity: O(1)
|
|
303
|
+
*
|
|
212
304
|
* Float operation to maintain heap properties after adding an element.
|
|
213
305
|
* @param index - The index of the newly added element.
|
|
214
306
|
*/
|
|
@@ -228,6 +320,14 @@ export class Heap<E = any> {
|
|
|
228
320
|
}
|
|
229
321
|
|
|
230
322
|
/**
|
|
323
|
+
* Time Complexity: O(log n)
|
|
324
|
+
* Space Complexity: O(1)
|
|
325
|
+
*/
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Time Complexity: O(log n)
|
|
329
|
+
* Space Complexity: O(1)
|
|
330
|
+
*
|
|
231
331
|
* Sinking operation to maintain heap properties after removing the top element.
|
|
232
332
|
* @param index - The index from which to start sinking.
|
|
233
333
|
*/
|
|
@@ -253,6 +353,14 @@ export class Heap<E = any> {
|
|
|
253
353
|
}
|
|
254
354
|
|
|
255
355
|
/**
|
|
356
|
+
* Time Complexity: O(n)
|
|
357
|
+
* Space Complexity: O(1)
|
|
358
|
+
*/
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Time Complexity: O(n)
|
|
362
|
+
* Space Complexity: O(1)
|
|
363
|
+
*
|
|
256
364
|
* Fix the entire heap to maintain heap properties.
|
|
257
365
|
*/
|
|
258
366
|
protected fix() {
|
|
@@ -321,7 +429,14 @@ export class FibonacciHeap<E> {
|
|
|
321
429
|
}
|
|
322
430
|
|
|
323
431
|
/**
|
|
324
|
-
* O(1)
|
|
432
|
+
* Time Complexity: O(1)
|
|
433
|
+
* Space Complexity: O(1)
|
|
434
|
+
*/
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Time Complexity: O(1)
|
|
438
|
+
* Space Complexity: O(1)
|
|
439
|
+
*
|
|
325
440
|
* Insert an element into the heap and maintain the heap properties.
|
|
326
441
|
* @param element
|
|
327
442
|
* @returns {FibonacciHeap<E>} FibonacciHeap<E> - The heap itself.
|
|
@@ -330,8 +445,16 @@ export class FibonacciHeap<E> {
|
|
|
330
445
|
return this.push(element);
|
|
331
446
|
}
|
|
332
447
|
|
|
448
|
+
|
|
333
449
|
/**
|
|
334
|
-
* O(1)
|
|
450
|
+
* Time Complexity: O(1)
|
|
451
|
+
* Space Complexity: O(1)
|
|
452
|
+
*/
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Time Complexity: O(1)
|
|
456
|
+
* Space Complexity: O(1)
|
|
457
|
+
*
|
|
335
458
|
* Insert an element into the heap and maintain the heap properties.
|
|
336
459
|
* @param element
|
|
337
460
|
* @returns {FibonacciHeap<E>} FibonacciHeap<E> - The heap itself.
|
|
@@ -350,8 +473,16 @@ export class FibonacciHeap<E> {
|
|
|
350
473
|
return this;
|
|
351
474
|
}
|
|
352
475
|
|
|
476
|
+
|
|
353
477
|
/**
|
|
354
|
-
* O(1)
|
|
478
|
+
* Time Complexity: O(1)
|
|
479
|
+
* Space Complexity: O(1)
|
|
480
|
+
*/
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Time Complexity: O(1)
|
|
484
|
+
* Space Complexity: O(1)
|
|
485
|
+
*
|
|
355
486
|
* Peek at the top element of the heap without removing it.
|
|
356
487
|
* @returns The top element or undefined if the heap is empty.
|
|
357
488
|
* @protected
|
|
@@ -361,7 +492,14 @@ export class FibonacciHeap<E> {
|
|
|
361
492
|
}
|
|
362
493
|
|
|
363
494
|
/**
|
|
364
|
-
* O(
|
|
495
|
+
* Time Complexity: O(n), where n is the number of nodes in the linked list.
|
|
496
|
+
* Space Complexity: O(1)
|
|
497
|
+
*/
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Time Complexity: O(n), where n is the number of nodes in the linked list.
|
|
501
|
+
* Space Complexity: O(1)
|
|
502
|
+
*
|
|
365
503
|
* Get the size (number of elements) of the heap.
|
|
366
504
|
* @param {FibonacciHeapNode<E>} head - The head of the linked list.
|
|
367
505
|
* @protected
|
|
@@ -388,8 +526,9 @@ export class FibonacciHeap<E> {
|
|
|
388
526
|
}
|
|
389
527
|
|
|
390
528
|
/**
|
|
391
|
-
* O(
|
|
392
|
-
*
|
|
529
|
+
* Time Complexity: O(1)
|
|
530
|
+
* Space Complexity: O(1)
|
|
531
|
+
*
|
|
393
532
|
* @param parent
|
|
394
533
|
* @param node
|
|
395
534
|
*/
|
|
@@ -405,7 +544,14 @@ export class FibonacciHeap<E> {
|
|
|
405
544
|
}
|
|
406
545
|
|
|
407
546
|
/**
|
|
408
|
-
* O(log n)
|
|
547
|
+
* Time Complexity: O(log n), where n is the number of nodes in the heap.
|
|
548
|
+
* Space Complexity: O(1)
|
|
549
|
+
*/
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Time Complexity: O(log n), where n is the number of nodes in the heap.
|
|
553
|
+
* Space Complexity: O(1)
|
|
554
|
+
*
|
|
409
555
|
* Remove and return the top element (smallest or largest element) from the heap.
|
|
410
556
|
* @returns The top element or undefined if the heap is empty.
|
|
411
557
|
*/
|
|
@@ -414,7 +560,14 @@ export class FibonacciHeap<E> {
|
|
|
414
560
|
}
|
|
415
561
|
|
|
416
562
|
/**
|
|
417
|
-
* O(log n)
|
|
563
|
+
* Time Complexity: O(log n), where n is the number of nodes in the heap.
|
|
564
|
+
* Space Complexity: O(1)
|
|
565
|
+
*/
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Time Complexity: O(log n), where n is the number of nodes in the heap.
|
|
569
|
+
* Space Complexity: O(1)
|
|
570
|
+
*
|
|
418
571
|
* Remove and return the top element (smallest or largest element) from the heap.
|
|
419
572
|
* @returns The top element or undefined if the heap is empty.
|
|
420
573
|
*/
|
|
@@ -446,7 +599,14 @@ export class FibonacciHeap<E> {
|
|
|
446
599
|
}
|
|
447
600
|
|
|
448
601
|
/**
|
|
449
|
-
* O(
|
|
602
|
+
* Time Complexity: O(1)
|
|
603
|
+
* Space Complexity: O(1)
|
|
604
|
+
*/
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Time Complexity: O(1)
|
|
608
|
+
* Space Complexity: O(1)
|
|
609
|
+
*
|
|
450
610
|
* merge two heaps. The heap that is merged will be cleared. The heap that is merged into will remain.
|
|
451
611
|
* @param heapToMerge
|
|
452
612
|
*/
|
|
@@ -504,6 +664,14 @@ export class FibonacciHeap<E> {
|
|
|
504
664
|
}
|
|
505
665
|
|
|
506
666
|
/**
|
|
667
|
+
* Time Complexity: O(1)
|
|
668
|
+
* Space Complexity: O(1)
|
|
669
|
+
*/
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* Time Complexity: O(1)
|
|
673
|
+
* Space Complexity: O(1)
|
|
674
|
+
*
|
|
507
675
|
* Merge the given node with the root list.
|
|
508
676
|
* @param node - The node to be merged.
|
|
509
677
|
*/
|
|
@@ -519,7 +687,14 @@ export class FibonacciHeap<E> {
|
|
|
519
687
|
}
|
|
520
688
|
|
|
521
689
|
/**
|
|
522
|
-
* O(
|
|
690
|
+
* Time Complexity: O(1)
|
|
691
|
+
* Space Complexity: O(1)
|
|
692
|
+
*/
|
|
693
|
+
|
|
694
|
+
/**
|
|
695
|
+
* Time Complexity: O(1)
|
|
696
|
+
* Space Complexity: O(1)
|
|
697
|
+
*.
|
|
523
698
|
* Remove and return the top element (smallest or largest element) from the heap.
|
|
524
699
|
* @param node - The node to be removed.
|
|
525
700
|
* @protected
|
|
@@ -531,7 +706,14 @@ export class FibonacciHeap<E> {
|
|
|
531
706
|
}
|
|
532
707
|
|
|
533
708
|
/**
|
|
534
|
-
* O(
|
|
709
|
+
* Time Complexity: O(1)
|
|
710
|
+
* Space Complexity: O(1)
|
|
711
|
+
*/
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* Time Complexity: O(1)
|
|
715
|
+
* Space Complexity: O(1)
|
|
716
|
+
*
|
|
535
717
|
* Remove and return the top element (smallest or largest element) from the heap.
|
|
536
718
|
* @param y
|
|
537
719
|
* @param x
|
|
@@ -547,7 +729,14 @@ export class FibonacciHeap<E> {
|
|
|
547
729
|
}
|
|
548
730
|
|
|
549
731
|
/**
|
|
550
|
-
* O(log n)
|
|
732
|
+
* Time Complexity: O(n log n), where n is the number of nodes in the heap.
|
|
733
|
+
* Space Complexity: O(n)
|
|
734
|
+
*/
|
|
735
|
+
|
|
736
|
+
/**
|
|
737
|
+
* Time Complexity: O(n log n), where n is the number of nodes in the heap.
|
|
738
|
+
* Space Complexity: O(n)
|
|
739
|
+
*
|
|
551
740
|
* Remove and return the top element (smallest or largest element) from the heap.
|
|
552
741
|
* @protected
|
|
553
742
|
*/
|