heap-typed 1.52.3 → 1.52.5
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/base/iterable-element-base.d.ts +1 -37
- package/dist/data-structures/base/iterable-element-base.js +1 -37
- package/dist/data-structures/base/iterable-entry-base.d.ts +2 -54
- package/dist/data-structures/base/iterable-entry-base.js +1 -49
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -32
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +9 -41
- package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -46
- package/dist/data-structures/binary-tree/avl-tree.js +0 -46
- package/dist/data-structures/binary-tree/binary-tree.d.ts +82 -147
- package/dist/data-structures/binary-tree/binary-tree.js +299 -331
- package/dist/data-structures/binary-tree/bst.d.ts +1 -40
- package/dist/data-structures/binary-tree/bst.js +12 -44
- package/dist/data-structures/binary-tree/rb-tree.d.ts +0 -48
- package/dist/data-structures/binary-tree/rb-tree.js +2 -50
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -32
- package/dist/data-structures/binary-tree/tree-multi-map.js +9 -41
- package/dist/data-structures/graph/abstract-graph.d.ts +0 -75
- package/dist/data-structures/graph/abstract-graph.js +0 -75
- package/dist/data-structures/graph/directed-graph.d.ts +0 -98
- package/dist/data-structures/graph/directed-graph.js +0 -98
- package/dist/data-structures/graph/undirected-graph.d.ts +0 -50
- package/dist/data-structures/graph/undirected-graph.js +0 -50
- package/dist/data-structures/hash/hash-map.d.ts +5 -92
- package/dist/data-structures/hash/hash-map.js +29 -115
- package/dist/data-structures/heap/heap.d.ts +0 -32
- package/dist/data-structures/heap/heap.js +0 -32
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +5 -88
- package/dist/data-structures/linked-list/doubly-linked-list.js +5 -88
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +1 -83
- package/dist/data-structures/linked-list/singly-linked-list.js +2 -84
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +1 -35
- package/dist/data-structures/linked-list/skip-linked-list.js +1 -35
- package/dist/data-structures/queue/deque.d.ts +1 -98
- package/dist/data-structures/queue/deque.js +3 -99
- package/dist/data-structures/queue/queue.d.ts +5 -58
- package/dist/data-structures/queue/queue.js +4 -57
- package/dist/data-structures/stack/stack.d.ts +1 -34
- package/dist/data-structures/stack/stack.js +1 -34
- package/dist/data-structures/tree/tree.js +2 -1
- package/dist/data-structures/trie/trie.d.ts +0 -64
- package/dist/data-structures/trie/trie.js +0 -64
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +8 -0
- package/dist/types/data-structures/binary-tree/binary-tree.js +6 -0
- package/dist/types/utils/utils.d.ts +13 -12
- package/dist/utils/number.d.ts +13 -0
- package/dist/utils/number.js +13 -0
- package/dist/utils/utils.d.ts +125 -3
- package/dist/utils/utils.js +177 -21
- package/package.json +2 -2
- package/src/data-structures/base/iterable-element-base.ts +2 -42
- package/src/data-structures/base/iterable-entry-base.ts +3 -62
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +8 -48
- package/src/data-structures/binary-tree/avl-tree.ts +0 -57
- package/src/data-structures/binary-tree/binary-tree.ts +329 -358
- package/src/data-structures/binary-tree/bst.ts +11 -54
- package/src/data-structures/binary-tree/rb-tree.ts +2 -62
- package/src/data-structures/binary-tree/tree-multi-map.ts +8 -48
- package/src/data-structures/graph/abstract-graph.ts +0 -92
- package/src/data-structures/graph/directed-graph.ts +0 -122
- package/src/data-structures/graph/undirected-graph.ts +0 -62
- package/src/data-structures/hash/hash-map.ts +31 -139
- package/src/data-structures/heap/heap.ts +0 -40
- package/src/data-structures/linked-list/doubly-linked-list.ts +5 -112
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -104
- package/src/data-structures/linked-list/skip-linked-list.ts +1 -44
- package/src/data-structures/queue/deque.ts +2 -125
- package/src/data-structures/queue/queue.ts +5 -72
- package/src/data-structures/stack/stack.ts +1 -43
- package/src/data-structures/tree/tree.ts +1 -1
- package/src/data-structures/trie/trie.ts +0 -80
- package/src/types/data-structures/binary-tree/binary-tree.ts +8 -1
- package/src/types/utils/utils.ts +17 -15
- package/src/utils/number.ts +13 -0
- package/src/utils/utils.ts +174 -18
|
@@ -23,6 +23,7 @@ import { BTNEntry } from '../../types';
|
|
|
23
23
|
import { BinaryTree, BinaryTreeNode } from './binary-tree';
|
|
24
24
|
import { IBinaryTree } from '../../interfaces';
|
|
25
25
|
import { Queue } from '../queue';
|
|
26
|
+
import { isComparable } from '../../utils';
|
|
26
27
|
|
|
27
28
|
export class BSTNode<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BSTNodeNested<K, V>> extends BinaryTreeNode<
|
|
28
29
|
K,
|
|
@@ -195,7 +196,7 @@ export class BST<
|
|
|
195
196
|
*/
|
|
196
197
|
override ensureNode(
|
|
197
198
|
keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>,
|
|
198
|
-
iterationType: IterationType =
|
|
199
|
+
iterationType: IterationType = this.iterationType
|
|
199
200
|
): OptBSTN<NODE> {
|
|
200
201
|
return super.ensureNode(keyOrNodeOrEntryOrRawElement, iterationType) ?? undefined;
|
|
201
202
|
}
|
|
@@ -213,6 +214,10 @@ export class BST<
|
|
|
213
214
|
return keyOrNodeOrEntryOrRawElement instanceof BSTNode;
|
|
214
215
|
}
|
|
215
216
|
|
|
217
|
+
override isKey(key: any): key is K {
|
|
218
|
+
return isComparable(key, this.comparator !== this._DEFAULT_COMPARATOR);
|
|
219
|
+
}
|
|
220
|
+
|
|
216
221
|
/**
|
|
217
222
|
* Time Complexity: O(log n)
|
|
218
223
|
* Space Complexity: O(1)
|
|
@@ -259,11 +264,6 @@ export class BST<
|
|
|
259
264
|
return false;
|
|
260
265
|
}
|
|
261
266
|
|
|
262
|
-
/**
|
|
263
|
-
* Time Complexity: O(log n)
|
|
264
|
-
* Space Complexity: O(log n)
|
|
265
|
-
*/
|
|
266
|
-
|
|
267
267
|
/**
|
|
268
268
|
* Time Complexity: O(k log n)
|
|
269
269
|
* Space Complexity: O(k + log n)
|
|
@@ -413,6 +413,8 @@ export class BST<
|
|
|
413
413
|
beginRoot: R | BTNKeyOrNodeOrEntry<K, V, NODE> = this.root,
|
|
414
414
|
iterationType: IterationType = this.iterationType
|
|
415
415
|
): NODE[] {
|
|
416
|
+
if (identifier === undefined) return [];
|
|
417
|
+
if (identifier === null) return [];
|
|
416
418
|
beginRoot = this.ensureNode(beginRoot);
|
|
417
419
|
if (!beginRoot) return [];
|
|
418
420
|
callback = this._ensureCallback(identifier, callback);
|
|
@@ -469,11 +471,6 @@ export class BST<
|
|
|
469
471
|
return ans;
|
|
470
472
|
}
|
|
471
473
|
|
|
472
|
-
/**
|
|
473
|
-
* Time Complexity: O(log n)
|
|
474
|
-
* Space Complexity: O(1)
|
|
475
|
-
*/
|
|
476
|
-
|
|
477
474
|
/**
|
|
478
475
|
* Time Complexity: O(log n)
|
|
479
476
|
* Space Complexity: O(1)
|
|
@@ -504,11 +501,6 @@ export class BST<
|
|
|
504
501
|
return this.getNodes(identifier, callback, true, beginRoot, iterationType)[0] ?? undefined;
|
|
505
502
|
}
|
|
506
503
|
|
|
507
|
-
/**
|
|
508
|
-
* Time Complexity: O(k log n)
|
|
509
|
-
* Space Complexity: O(k + log n)
|
|
510
|
-
*/
|
|
511
|
-
|
|
512
504
|
/**
|
|
513
505
|
* Time Complexity: O(log n)
|
|
514
506
|
* Space Complexity: O(1)
|
|
@@ -522,15 +514,10 @@ export class BST<
|
|
|
522
514
|
* It has a default value of `'ITERATIVE'`.
|
|
523
515
|
* @returns The method is returning a NODE object or undefined.
|
|
524
516
|
*/
|
|
525
|
-
override getNodeByKey(key: K, iterationType: IterationType =
|
|
517
|
+
override getNodeByKey(key: K, iterationType: IterationType = this.iterationType): OptBSTN<NODE> {
|
|
526
518
|
return this.getNode(key, this._DEFAULT_CALLBACK, this.root, iterationType);
|
|
527
519
|
}
|
|
528
520
|
|
|
529
|
-
/**
|
|
530
|
-
* Time Complexity: O(log n)
|
|
531
|
-
* Space Complexity: O(k + log n)
|
|
532
|
-
*/
|
|
533
|
-
|
|
534
521
|
/**
|
|
535
522
|
* Time complexity: O(n)
|
|
536
523
|
* Space complexity: O(n)
|
|
@@ -555,16 +542,11 @@ export class BST<
|
|
|
555
542
|
callback: C = this._DEFAULT_CALLBACK as C,
|
|
556
543
|
pattern: DFSOrderPattern = 'IN',
|
|
557
544
|
beginRoot: R | BTNKeyOrNodeOrEntry<K, V, NODE> = this.root,
|
|
558
|
-
iterationType: IterationType =
|
|
545
|
+
iterationType: IterationType = this.iterationType
|
|
559
546
|
): ReturnType<C>[] {
|
|
560
|
-
return super.dfs(callback, pattern, beginRoot, iterationType
|
|
547
|
+
return super.dfs(callback, pattern, beginRoot, iterationType);
|
|
561
548
|
}
|
|
562
549
|
|
|
563
|
-
/**
|
|
564
|
-
* Time Complexity: O(log n)
|
|
565
|
-
* Space Complexity: O(1)
|
|
566
|
-
*/
|
|
567
|
-
|
|
568
550
|
/**
|
|
569
551
|
* Time complexity: O(n)
|
|
570
552
|
* Space complexity: O(n)
|
|
@@ -590,11 +572,6 @@ export class BST<
|
|
|
590
572
|
return super.bfs(callback, beginRoot, iterationType, false);
|
|
591
573
|
}
|
|
592
574
|
|
|
593
|
-
/**
|
|
594
|
-
* Time Complexity: O(log n)
|
|
595
|
-
* Space Complexity: O(1)
|
|
596
|
-
*/
|
|
597
|
-
|
|
598
575
|
/**
|
|
599
576
|
* Time complexity: O(n)
|
|
600
577
|
* Space complexity: O(n)
|
|
@@ -621,11 +598,6 @@ export class BST<
|
|
|
621
598
|
return super.listLevels(callback, beginRoot, iterationType, false);
|
|
622
599
|
}
|
|
623
600
|
|
|
624
|
-
/**
|
|
625
|
-
* Time complexity: O(n)
|
|
626
|
-
* Space complexity: O(n)
|
|
627
|
-
*/
|
|
628
|
-
|
|
629
601
|
/**
|
|
630
602
|
* Time complexity: O(n)
|
|
631
603
|
* Space complexity: O(n)
|
|
@@ -687,11 +659,6 @@ export class BST<
|
|
|
687
659
|
}
|
|
688
660
|
}
|
|
689
661
|
|
|
690
|
-
/**
|
|
691
|
-
* Time complexity: O(n)
|
|
692
|
-
* Space complexity: O(n)
|
|
693
|
-
*/
|
|
694
|
-
|
|
695
662
|
/**
|
|
696
663
|
* Time complexity: O(n)
|
|
697
664
|
* Space complexity: O(n)
|
|
@@ -741,11 +708,6 @@ export class BST<
|
|
|
741
708
|
}
|
|
742
709
|
}
|
|
743
710
|
|
|
744
|
-
/**
|
|
745
|
-
* Time complexity: O(n)
|
|
746
|
-
* Space complexity: O(n)
|
|
747
|
-
*/
|
|
748
|
-
|
|
749
711
|
/**
|
|
750
712
|
* Time Complexity: O(n)
|
|
751
713
|
* Space Complexity: O(log n)
|
|
@@ -815,11 +777,6 @@ export class BST<
|
|
|
815
777
|
|
|
816
778
|
protected _comparator: Comparator<K> = this._DEFAULT_COMPARATOR;
|
|
817
779
|
|
|
818
|
-
/**
|
|
819
|
-
* Time Complexity: O(n)
|
|
820
|
-
* Space Complexity: O(log n)
|
|
821
|
-
*/
|
|
822
|
-
|
|
823
780
|
/**
|
|
824
781
|
* The function returns the value of the _comparator property.
|
|
825
782
|
* @returns The `_comparator` property is being returned.
|
|
@@ -126,11 +126,6 @@ export class RedBlackTree<
|
|
|
126
126
|
}) as TREE;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
/**
|
|
130
|
-
* Time Complexity: O(1)
|
|
131
|
-
* Space Complexity: O(1)
|
|
132
|
-
*/
|
|
133
|
-
|
|
134
129
|
/**
|
|
135
130
|
* Time Complexity: O(1)
|
|
136
131
|
* Space Complexity: O(1)
|
|
@@ -169,7 +164,7 @@ export class RedBlackTree<
|
|
|
169
164
|
//
|
|
170
165
|
// if (this.toEntryFn) {
|
|
171
166
|
// const [key, entryValue] = this.toEntryFn(keyOrNodeOrEntryOrRawElement as R);
|
|
172
|
-
// if (key) return this.createNode(key, entryValue ?? value, 'RED');
|
|
167
|
+
// if (this.isKey(key)) return this.createNode(key, entryValue ?? value, 'RED');
|
|
173
168
|
// }
|
|
174
169
|
//
|
|
175
170
|
// if (this.isEntry(keyOrNodeOrEntryOrRawElement)) {
|
|
@@ -183,11 +178,6 @@ export class RedBlackTree<
|
|
|
183
178
|
// return ;
|
|
184
179
|
// }
|
|
185
180
|
|
|
186
|
-
/**
|
|
187
|
-
* Time Complexity: O(1)
|
|
188
|
-
* Space Complexity: O(1)
|
|
189
|
-
*/
|
|
190
|
-
|
|
191
181
|
/**
|
|
192
182
|
* Time Complexity: O(1)
|
|
193
183
|
* Space Complexity: O(1)
|
|
@@ -200,11 +190,6 @@ export class RedBlackTree<
|
|
|
200
190
|
this._root = this.NIL;
|
|
201
191
|
}
|
|
202
192
|
|
|
203
|
-
/**
|
|
204
|
-
* Time Complexity: O(log n)
|
|
205
|
-
* Space Complexity: O(1)
|
|
206
|
-
*/
|
|
207
|
-
|
|
208
193
|
/**
|
|
209
194
|
* Time Complexity: O(log n)
|
|
210
195
|
* Space Complexity: O(1)
|
|
@@ -238,11 +223,6 @@ export class RedBlackTree<
|
|
|
238
223
|
} else return insertStatus === 'UPDATED';
|
|
239
224
|
}
|
|
240
225
|
|
|
241
|
-
/**
|
|
242
|
-
* Time Complexity: O(log n)
|
|
243
|
-
* Space Complexity: O(1)
|
|
244
|
-
*/
|
|
245
|
-
|
|
246
226
|
/**
|
|
247
227
|
* Time Complexity: O(log n)
|
|
248
228
|
* Space Complexity: O(1)
|
|
@@ -282,7 +262,7 @@ export class RedBlackTree<
|
|
|
282
262
|
replacementNode = nodeToDelete.left;
|
|
283
263
|
this._transplant(nodeToDelete, nodeToDelete.left);
|
|
284
264
|
} else {
|
|
285
|
-
const successor = this.getLeftMost(nodeToDelete.right);
|
|
265
|
+
const successor = this.getLeftMost(node => node, nodeToDelete.right);
|
|
286
266
|
if (successor) {
|
|
287
267
|
originalColor = successor.color;
|
|
288
268
|
replacementNode = successor.right;
|
|
@@ -319,11 +299,6 @@ export class RedBlackTree<
|
|
|
319
299
|
return results;
|
|
320
300
|
}
|
|
321
301
|
|
|
322
|
-
/**
|
|
323
|
-
* Time Complexity: O(1)
|
|
324
|
-
* Space Complexity: O(1)
|
|
325
|
-
*/
|
|
326
|
-
|
|
327
302
|
/**
|
|
328
303
|
* Time Complexity: O(1)
|
|
329
304
|
* Space Complexity: O(1)
|
|
@@ -339,11 +314,6 @@ export class RedBlackTree<
|
|
|
339
314
|
this._root = v;
|
|
340
315
|
}
|
|
341
316
|
|
|
342
|
-
/**
|
|
343
|
-
* Time Complexity: O(1)
|
|
344
|
-
* Space Complexity: O(1)
|
|
345
|
-
*/
|
|
346
|
-
|
|
347
317
|
/**
|
|
348
318
|
* Time Complexity: O(1)
|
|
349
319
|
* Space Complexity: O(1)
|
|
@@ -362,11 +332,6 @@ export class RedBlackTree<
|
|
|
362
332
|
return super._replaceNode(oldNode, newNode);
|
|
363
333
|
}
|
|
364
334
|
|
|
365
|
-
/**
|
|
366
|
-
* Time Complexity: O(log n)
|
|
367
|
-
* Space Complexity: O(1)
|
|
368
|
-
*/
|
|
369
|
-
|
|
370
335
|
/**
|
|
371
336
|
* Time Complexity: O(log n)
|
|
372
337
|
* Space Complexity: O(1)
|
|
@@ -414,11 +379,6 @@ export class RedBlackTree<
|
|
|
414
379
|
return 'CREATED';
|
|
415
380
|
}
|
|
416
381
|
|
|
417
|
-
/**
|
|
418
|
-
* Time Complexity: O(1)
|
|
419
|
-
* Space Complexity: O(1)
|
|
420
|
-
*/
|
|
421
|
-
|
|
422
382
|
/**
|
|
423
383
|
* Time Complexity: O(1)
|
|
424
384
|
* Space Complexity: O(1)
|
|
@@ -442,11 +402,6 @@ export class RedBlackTree<
|
|
|
442
402
|
}
|
|
443
403
|
}
|
|
444
404
|
|
|
445
|
-
/**
|
|
446
|
-
* Time Complexity: O(log n)
|
|
447
|
-
* Space Complexity: O(1)
|
|
448
|
-
*/
|
|
449
|
-
|
|
450
405
|
/**
|
|
451
406
|
* Time Complexity: O(log n)
|
|
452
407
|
* Space Complexity: O(1)
|
|
@@ -513,11 +468,6 @@ export class RedBlackTree<
|
|
|
513
468
|
if (this.isRealNode(this._root)) this._root.color = 'BLACK';
|
|
514
469
|
}
|
|
515
470
|
|
|
516
|
-
/**
|
|
517
|
-
* Time Complexity: O(log n)
|
|
518
|
-
* Space Complexity: O(1)
|
|
519
|
-
*/
|
|
520
|
-
|
|
521
471
|
/**
|
|
522
472
|
* Time Complexity: O(log n)
|
|
523
473
|
* Space Complexity: O(1)
|
|
@@ -601,11 +551,6 @@ export class RedBlackTree<
|
|
|
601
551
|
}
|
|
602
552
|
}
|
|
603
553
|
|
|
604
|
-
/**
|
|
605
|
-
* Time Complexity: O(1)
|
|
606
|
-
* Space Complexity: O(1)
|
|
607
|
-
*/
|
|
608
|
-
|
|
609
554
|
/**
|
|
610
555
|
* Time Complexity: O(1)
|
|
611
556
|
* Space Complexity: O(1)
|
|
@@ -641,11 +586,6 @@ export class RedBlackTree<
|
|
|
641
586
|
x.parent = y;
|
|
642
587
|
}
|
|
643
588
|
|
|
644
|
-
/**
|
|
645
|
-
* Time Complexity: O(1)
|
|
646
|
-
* Space Complexity: O(1)
|
|
647
|
-
*/
|
|
648
|
-
|
|
649
589
|
/**
|
|
650
590
|
* Time Complexity: O(1)
|
|
651
591
|
* Space Complexity: O(1)
|
|
@@ -100,11 +100,6 @@ export class TreeMultiMap<
|
|
|
100
100
|
return this._count;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
/**
|
|
104
|
-
* Time Complexity: O(n)
|
|
105
|
-
* Space Complexity: O(1)
|
|
106
|
-
*/
|
|
107
|
-
|
|
108
103
|
/**
|
|
109
104
|
* Time Complexity: O(n)
|
|
110
105
|
* Space Complexity: O(1)
|
|
@@ -172,15 +167,15 @@ export class TreeMultiMap<
|
|
|
172
167
|
|
|
173
168
|
if (this.isNode(keyOrNodeOrEntryOrRawElement)) return keyOrNodeOrEntryOrRawElement;
|
|
174
169
|
|
|
175
|
-
if (this.toEntryFn) {
|
|
176
|
-
const [key] = this.toEntryFn(keyOrNodeOrEntryOrRawElement as R);
|
|
177
|
-
if (key) return this.getNodeByKey(key);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
170
|
if (this.isEntry(keyOrNodeOrEntryOrRawElement)) {
|
|
181
|
-
const [key,
|
|
171
|
+
const [key, entryValue] = keyOrNodeOrEntryOrRawElement;
|
|
182
172
|
if (key === undefined || key === null) return;
|
|
183
|
-
|
|
173
|
+
if (this.isKey(key)) return this.createNode(key, value ?? entryValue, 'BLACK', count);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (this.toEntryFn) {
|
|
177
|
+
const [key, entryValue] = this.toEntryFn(keyOrNodeOrEntryOrRawElement as R);
|
|
178
|
+
if (this.isKey(key)) return this.createNode(key, value ?? entryValue, 'BLACK', count);
|
|
184
179
|
}
|
|
185
180
|
|
|
186
181
|
if (this.isKey(keyOrNodeOrEntryOrRawElement))
|
|
@@ -202,11 +197,6 @@ export class TreeMultiMap<
|
|
|
202
197
|
return keyOrNodeOrEntryOrRawElement instanceof TreeMultiMapNode;
|
|
203
198
|
}
|
|
204
199
|
|
|
205
|
-
/**
|
|
206
|
-
* Time Complexity: O(log n)
|
|
207
|
-
* Space Complexity: O(1)
|
|
208
|
-
*/
|
|
209
|
-
|
|
210
200
|
/**
|
|
211
201
|
* Time Complexity: O(log n)
|
|
212
202
|
* Space Complexity: O(1)
|
|
@@ -236,11 +226,6 @@ export class TreeMultiMap<
|
|
|
236
226
|
}
|
|
237
227
|
}
|
|
238
228
|
|
|
239
|
-
/**
|
|
240
|
-
* Time Complexity: O(log n)
|
|
241
|
-
* Space Complexity: O(1)
|
|
242
|
-
*/
|
|
243
|
-
|
|
244
229
|
/**
|
|
245
230
|
* Time Complexity: O(log n)
|
|
246
231
|
* Space Complexity: O(1)
|
|
@@ -300,7 +285,7 @@ export class TreeMultiMap<
|
|
|
300
285
|
return results;
|
|
301
286
|
}
|
|
302
287
|
} else {
|
|
303
|
-
const successor = this.getLeftMost(nodeToDelete.right);
|
|
288
|
+
const successor = this.getLeftMost(node => node, nodeToDelete.right);
|
|
304
289
|
if (successor) {
|
|
305
290
|
originalColor = successor.color;
|
|
306
291
|
replacementNode = successor.right;
|
|
@@ -352,11 +337,6 @@ export class TreeMultiMap<
|
|
|
352
337
|
return results;
|
|
353
338
|
}
|
|
354
339
|
|
|
355
|
-
/**
|
|
356
|
-
* Time Complexity: O(1)
|
|
357
|
-
* Space Complexity: O(1)
|
|
358
|
-
*/
|
|
359
|
-
|
|
360
340
|
/**
|
|
361
341
|
* Time Complexity: O(1)
|
|
362
342
|
* Space Complexity: O(1)
|
|
@@ -369,11 +349,6 @@ export class TreeMultiMap<
|
|
|
369
349
|
this._count = 0;
|
|
370
350
|
}
|
|
371
351
|
|
|
372
|
-
/**
|
|
373
|
-
* Time Complexity: O(n log n)
|
|
374
|
-
* Space Complexity: O(log n)
|
|
375
|
-
*/
|
|
376
|
-
|
|
377
352
|
/**
|
|
378
353
|
* Time Complexity: O(n log n)
|
|
379
354
|
* Space Complexity: O(log n)
|
|
@@ -425,11 +400,6 @@ export class TreeMultiMap<
|
|
|
425
400
|
}
|
|
426
401
|
}
|
|
427
402
|
|
|
428
|
-
/**
|
|
429
|
-
* Time complexity: O(n)
|
|
430
|
-
* Space complexity: O(n)
|
|
431
|
-
*/
|
|
432
|
-
|
|
433
403
|
/**
|
|
434
404
|
* Time complexity: O(n)
|
|
435
405
|
* Space complexity: O(n)
|
|
@@ -443,11 +413,6 @@ export class TreeMultiMap<
|
|
|
443
413
|
return cloned;
|
|
444
414
|
}
|
|
445
415
|
|
|
446
|
-
/**
|
|
447
|
-
* Time Complexity: O(1)
|
|
448
|
-
* Space Complexity: O(1)
|
|
449
|
-
*/
|
|
450
|
-
|
|
451
416
|
/**
|
|
452
417
|
* Time Complexity: O(1)
|
|
453
418
|
* Space Complexity: O(1)
|
|
@@ -490,11 +455,6 @@ export class TreeMultiMap<
|
|
|
490
455
|
return undefined;
|
|
491
456
|
}
|
|
492
457
|
|
|
493
|
-
/**
|
|
494
|
-
* Time Complexity: O(1)
|
|
495
|
-
* Space Complexity: O(1)
|
|
496
|
-
*/
|
|
497
|
-
|
|
498
458
|
/**
|
|
499
459
|
* Time Complexity: O(1)
|
|
500
460
|
* Space Complexity: O(1)
|
|
@@ -119,11 +119,6 @@ export abstract class AbstractGraph<
|
|
|
119
119
|
|
|
120
120
|
abstract getEndsOfEdge(edge: EO): [VO, VO] | undefined;
|
|
121
121
|
|
|
122
|
-
/**
|
|
123
|
-
* Time Complexity: O(1) - Constant time for Map lookup.
|
|
124
|
-
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
125
|
-
*/
|
|
126
|
-
|
|
127
122
|
/**
|
|
128
123
|
* Time Complexity: O(1) - Constant time for Map lookup.
|
|
129
124
|
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
@@ -138,11 +133,6 @@ export abstract class AbstractGraph<
|
|
|
138
133
|
return this._vertexMap.get(vertexKey) || undefined;
|
|
139
134
|
}
|
|
140
135
|
|
|
141
|
-
/**
|
|
142
|
-
* Time Complexity: O(1) - Constant time for Map lookup.
|
|
143
|
-
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
144
|
-
*/
|
|
145
|
-
|
|
146
136
|
/**
|
|
147
137
|
* Time Complexity: O(1) - Constant time for Map lookup.
|
|
148
138
|
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
@@ -186,11 +176,6 @@ export abstract class AbstractGraph<
|
|
|
186
176
|
|
|
187
177
|
abstract deleteVertex(vertexOrKey: VO | VertexKey): boolean;
|
|
188
178
|
|
|
189
|
-
/**
|
|
190
|
-
* Time Complexity: O(K), where K is the number of vertexMap to be removed.
|
|
191
|
-
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
192
|
-
*/
|
|
193
|
-
|
|
194
179
|
/**
|
|
195
180
|
* Time Complexity: O(K), where K is the number of vertexMap to be removed.
|
|
196
181
|
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
@@ -209,11 +194,6 @@ export abstract class AbstractGraph<
|
|
|
209
194
|
return removed.length > 0;
|
|
210
195
|
}
|
|
211
196
|
|
|
212
|
-
/**
|
|
213
|
-
* Time Complexity: O(1) - Depends on the implementation in the concrete class.
|
|
214
|
-
* Space Complexity: O(1) - Depends on the implementation in the concrete class.
|
|
215
|
-
*/
|
|
216
|
-
|
|
217
197
|
/**
|
|
218
198
|
* Time Complexity: O(1) - Depends on the implementation in the concrete class.
|
|
219
199
|
* Space Complexity: O(1) - Depends on the implementation in the concrete class.
|
|
@@ -255,11 +235,6 @@ export abstract class AbstractGraph<
|
|
|
255
235
|
}
|
|
256
236
|
}
|
|
257
237
|
|
|
258
|
-
/**
|
|
259
|
-
* Time Complexity: O(1) - Constant time for Map and Edge operations.
|
|
260
|
-
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
261
|
-
*/
|
|
262
|
-
|
|
263
238
|
/**
|
|
264
239
|
* Time Complexity: O(1) - Constant time for Map and Edge operations.
|
|
265
240
|
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
@@ -284,11 +259,6 @@ export abstract class AbstractGraph<
|
|
|
284
259
|
}
|
|
285
260
|
}
|
|
286
261
|
|
|
287
|
-
/**
|
|
288
|
-
* Time Complexity: O(P), where P is the number of paths found (in the worst case, exploring all paths).
|
|
289
|
-
* Space Complexity: O(P) - Linear space, where P is the number of paths found.
|
|
290
|
-
*/
|
|
291
|
-
|
|
292
262
|
/**
|
|
293
263
|
* Time Complexity: O(P), where P is the number of paths found (in the worst case, exploring all paths).
|
|
294
264
|
* Space Complexity: O(P) - Linear space, where P is the number of paths found.
|
|
@@ -331,11 +301,6 @@ export abstract class AbstractGraph<
|
|
|
331
301
|
return paths;
|
|
332
302
|
}
|
|
333
303
|
|
|
334
|
-
/**
|
|
335
|
-
* Time Complexity: O(L), where L is the length of the path.
|
|
336
|
-
* Space Complexity: O(1) - Constant space.
|
|
337
|
-
*/
|
|
338
|
-
|
|
339
304
|
/**
|
|
340
305
|
* Time Complexity: O(L), where L is the length of the path.
|
|
341
306
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -352,11 +317,6 @@ export abstract class AbstractGraph<
|
|
|
352
317
|
return sum;
|
|
353
318
|
}
|
|
354
319
|
|
|
355
|
-
/**
|
|
356
|
-
* Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
|
|
357
|
-
* Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
|
|
358
|
-
*/
|
|
359
|
-
|
|
360
320
|
/**
|
|
361
321
|
* Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
|
|
362
322
|
* Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
|
|
@@ -419,11 +379,6 @@ export abstract class AbstractGraph<
|
|
|
419
379
|
}
|
|
420
380
|
}
|
|
421
381
|
|
|
422
|
-
/**
|
|
423
|
-
* Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
|
|
424
|
-
* Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
|
|
425
|
-
*/
|
|
426
|
-
|
|
427
382
|
/**
|
|
428
383
|
* Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
|
|
429
384
|
* Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
|
|
@@ -495,15 +450,6 @@ export abstract class AbstractGraph<
|
|
|
495
450
|
}
|
|
496
451
|
}
|
|
497
452
|
|
|
498
|
-
/**
|
|
499
|
-
* Dijkstra algorithm time: O(VE) space: O(VO + EO)
|
|
500
|
-
*/
|
|
501
|
-
|
|
502
|
-
/**
|
|
503
|
-
* Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization).
|
|
504
|
-
* Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
|
|
505
|
-
*/
|
|
506
|
-
|
|
507
453
|
/**
|
|
508
454
|
* Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization).
|
|
509
455
|
* Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
|
|
@@ -633,20 +579,6 @@ export abstract class AbstractGraph<
|
|
|
633
579
|
return { distMap, preMap, seen, paths, minDist, minPath };
|
|
634
580
|
}
|
|
635
581
|
|
|
636
|
-
/**
|
|
637
|
-
* Dijkstra algorithm time: O(logVE) space: O(VO + EO)
|
|
638
|
-
*
|
|
639
|
-
* Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
|
|
640
|
-
* Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edgeMap.
|
|
641
|
-
* The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(VO^3), where VO is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
|
|
642
|
-
*
|
|
643
|
-
*/
|
|
644
|
-
|
|
645
|
-
/**
|
|
646
|
-
* Time Complexity: O((V + E) * log(V)) - Depends on the implementation (using a binary heap).
|
|
647
|
-
* Space Complexity: O(V + E) - Depends on the implementation (using a binary heap).
|
|
648
|
-
*/
|
|
649
|
-
|
|
650
582
|
/**
|
|
651
583
|
* Time Complexity: O((V + E) * log(V)) - Depends on the implementation (using a binary heap).
|
|
652
584
|
* Space Complexity: O(V + E) - Depends on the implementation (using a binary heap).
|
|
@@ -774,12 +706,6 @@ export abstract class AbstractGraph<
|
|
|
774
706
|
return { distMap, preMap, seen, paths, minDist, minPath };
|
|
775
707
|
}
|
|
776
708
|
|
|
777
|
-
/**
|
|
778
|
-
* Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
|
|
779
|
-
* Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
|
|
780
|
-
* one to rest pairs
|
|
781
|
-
*/
|
|
782
|
-
|
|
783
709
|
/**
|
|
784
710
|
* Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
|
|
785
711
|
* Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
|
|
@@ -902,14 +828,6 @@ export abstract class AbstractGraph<
|
|
|
902
828
|
* The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
|
|
903
829
|
*/
|
|
904
830
|
|
|
905
|
-
/**
|
|
906
|
-
* Time Complexity: O(V^3) - Cubic time (Floyd-Warshall algorithm).
|
|
907
|
-
* Space Complexity: O(V^2) - Quadratic space (Floyd-Warshall algorithm).
|
|
908
|
-
* Not support graph with negative weight cycle
|
|
909
|
-
* all pairs
|
|
910
|
-
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edgeMap, and it can simultaneously compute shortest paths between any two nodes.
|
|
911
|
-
*/
|
|
912
|
-
|
|
913
831
|
/**
|
|
914
832
|
* Time Complexity: O(V^3) - Cubic time (Floyd-Warshall algorithm).
|
|
915
833
|
* Space Complexity: O(V^2) - Quadratic space (Floyd-Warshall algorithm).
|
|
@@ -1009,11 +927,6 @@ export abstract class AbstractGraph<
|
|
|
1009
927
|
return [...uniqueCycles].map(cycleString => cycleString[1]);
|
|
1010
928
|
}
|
|
1011
929
|
|
|
1012
|
-
/**
|
|
1013
|
-
* Time Complexity: O(n)
|
|
1014
|
-
* Space Complexity: O(n)
|
|
1015
|
-
*/
|
|
1016
|
-
|
|
1017
930
|
/**
|
|
1018
931
|
* Time Complexity: O(n)
|
|
1019
932
|
* Space Complexity: O(n)
|
|
@@ -1042,11 +955,6 @@ export abstract class AbstractGraph<
|
|
|
1042
955
|
return filtered;
|
|
1043
956
|
}
|
|
1044
957
|
|
|
1045
|
-
/**
|
|
1046
|
-
* Time Complexity: O(n)
|
|
1047
|
-
* Space Complexity: O(n)
|
|
1048
|
-
*/
|
|
1049
|
-
|
|
1050
958
|
/**
|
|
1051
959
|
* Time Complexity: O(n)
|
|
1052
960
|
* Space Complexity: O(n)
|