avl-tree-typed 1.52.4 → 1.52.6

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 (74) hide show
  1. package/dist/data-structures/base/iterable-element-base.d.ts +1 -37
  2. package/dist/data-structures/base/iterable-element-base.js +1 -37
  3. package/dist/data-structures/base/iterable-entry-base.d.ts +2 -54
  4. package/dist/data-structures/base/iterable-entry-base.js +1 -49
  5. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -32
  6. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +9 -41
  7. package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -46
  8. package/dist/data-structures/binary-tree/avl-tree.js +0 -46
  9. package/dist/data-structures/binary-tree/binary-tree.d.ts +82 -147
  10. package/dist/data-structures/binary-tree/binary-tree.js +300 -332
  11. package/dist/data-structures/binary-tree/bst.d.ts +1 -40
  12. package/dist/data-structures/binary-tree/bst.js +12 -44
  13. package/dist/data-structures/binary-tree/rb-tree.d.ts +0 -48
  14. package/dist/data-structures/binary-tree/rb-tree.js +2 -50
  15. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -32
  16. package/dist/data-structures/binary-tree/tree-multi-map.js +9 -41
  17. package/dist/data-structures/graph/abstract-graph.d.ts +0 -75
  18. package/dist/data-structures/graph/abstract-graph.js +0 -75
  19. package/dist/data-structures/graph/directed-graph.d.ts +0 -98
  20. package/dist/data-structures/graph/directed-graph.js +0 -98
  21. package/dist/data-structures/graph/undirected-graph.d.ts +0 -50
  22. package/dist/data-structures/graph/undirected-graph.js +0 -50
  23. package/dist/data-structures/hash/hash-map.d.ts +5 -92
  24. package/dist/data-structures/hash/hash-map.js +27 -111
  25. package/dist/data-structures/heap/heap.d.ts +0 -32
  26. package/dist/data-structures/heap/heap.js +0 -32
  27. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +5 -88
  28. package/dist/data-structures/linked-list/doubly-linked-list.js +5 -88
  29. package/dist/data-structures/linked-list/singly-linked-list.d.ts +1 -83
  30. package/dist/data-structures/linked-list/singly-linked-list.js +2 -84
  31. package/dist/data-structures/linked-list/skip-linked-list.d.ts +1 -35
  32. package/dist/data-structures/linked-list/skip-linked-list.js +1 -35
  33. package/dist/data-structures/queue/deque.d.ts +1 -98
  34. package/dist/data-structures/queue/deque.js +3 -99
  35. package/dist/data-structures/queue/queue.d.ts +1 -54
  36. package/dist/data-structures/queue/queue.js +0 -53
  37. package/dist/data-structures/stack/stack.d.ts +1 -34
  38. package/dist/data-structures/stack/stack.js +1 -34
  39. package/dist/data-structures/tree/tree.js +2 -1
  40. package/dist/data-structures/trie/trie.d.ts +0 -64
  41. package/dist/data-structures/trie/trie.js +0 -64
  42. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +8 -0
  43. package/dist/types/data-structures/binary-tree/binary-tree.js +6 -0
  44. package/dist/types/utils/utils.d.ts +13 -12
  45. package/dist/utils/number.d.ts +13 -0
  46. package/dist/utils/number.js +13 -0
  47. package/dist/utils/utils.d.ts +125 -3
  48. package/dist/utils/utils.js +177 -21
  49. package/package.json +2 -2
  50. package/src/data-structures/base/iterable-element-base.ts +2 -42
  51. package/src/data-structures/base/iterable-entry-base.ts +3 -62
  52. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +8 -48
  53. package/src/data-structures/binary-tree/avl-tree.ts +0 -57
  54. package/src/data-structures/binary-tree/binary-tree.ts +330 -359
  55. package/src/data-structures/binary-tree/bst.ts +11 -54
  56. package/src/data-structures/binary-tree/rb-tree.ts +2 -62
  57. package/src/data-structures/binary-tree/tree-multi-map.ts +8 -48
  58. package/src/data-structures/graph/abstract-graph.ts +0 -92
  59. package/src/data-structures/graph/directed-graph.ts +0 -122
  60. package/src/data-structures/graph/undirected-graph.ts +0 -62
  61. package/src/data-structures/hash/hash-map.ts +29 -133
  62. package/src/data-structures/heap/heap.ts +0 -40
  63. package/src/data-structures/linked-list/doubly-linked-list.ts +5 -112
  64. package/src/data-structures/linked-list/singly-linked-list.ts +2 -104
  65. package/src/data-structures/linked-list/skip-linked-list.ts +1 -44
  66. package/src/data-structures/queue/deque.ts +2 -125
  67. package/src/data-structures/queue/queue.ts +1 -68
  68. package/src/data-structures/stack/stack.ts +1 -43
  69. package/src/data-structures/tree/tree.ts +1 -1
  70. package/src/data-structures/trie/trie.ts +0 -80
  71. package/src/types/data-structures/binary-tree/binary-tree.ts +8 -1
  72. package/src/types/utils/utils.ts +17 -15
  73. package/src/utils/number.ts +13 -0
  74. package/src/utils/utils.ts +174 -18
@@ -61,10 +61,6 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
61
61
  get count() {
62
62
  return this._count;
63
63
  }
64
- /**
65
- * Time Complexity: O(n)
66
- * Space Complexity: O(1)
67
- */
68
64
  /**
69
65
  * Time Complexity: O(n)
70
66
  * Space Complexity: O(1)
@@ -122,17 +118,17 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
122
118
  return;
123
119
  if (this.isNode(keyOrNodeOrEntryOrRawElement))
124
120
  return keyOrNodeOrEntryOrRawElement;
125
- if (this.toEntryFn) {
126
- const [key] = this.toEntryFn(keyOrNodeOrEntryOrRawElement);
127
- if (key)
128
- return this.getNodeByKey(key);
129
- }
130
121
  if (this.isEntry(keyOrNodeOrEntryOrRawElement)) {
131
- const [key, value] = keyOrNodeOrEntryOrRawElement;
122
+ const [key, entryValue] = keyOrNodeOrEntryOrRawElement;
132
123
  if (key === undefined || key === null)
133
124
  return;
134
- else
135
- return this.createNode(key, value, 'BLACK', count);
125
+ if (this.isKey(key))
126
+ return this.createNode(key, value !== null && value !== void 0 ? value : entryValue, 'BLACK', count);
127
+ }
128
+ if (this.toEntryFn) {
129
+ const [key, entryValue] = this.toEntryFn(keyOrNodeOrEntryOrRawElement);
130
+ if (this.isKey(key))
131
+ return this.createNode(key, value !== null && value !== void 0 ? value : entryValue, 'BLACK', count);
136
132
  }
137
133
  if (this.isKey(keyOrNodeOrEntryOrRawElement))
138
134
  return this.createNode(keyOrNodeOrEntryOrRawElement, value, 'BLACK', count);
@@ -148,10 +144,6 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
148
144
  isNode(keyOrNodeOrEntryOrRawElement) {
149
145
  return keyOrNodeOrEntryOrRawElement instanceof TreeMultiMapNode;
150
146
  }
151
- /**
152
- * Time Complexity: O(log n)
153
- * Space Complexity: O(1)
154
- */
155
147
  /**
156
148
  * Time Complexity: O(log n)
157
149
  * Space Complexity: O(1)
@@ -180,10 +172,6 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
180
172
  return false;
181
173
  }
182
174
  }
183
- /**
184
- * Time Complexity: O(log n)
185
- * Space Complexity: O(1)
186
- */
187
175
  /**
188
176
  * Time Complexity: O(log n)
189
177
  * Space Complexity: O(1)
@@ -240,7 +228,7 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
240
228
  }
241
229
  }
242
230
  else {
243
- const successor = this.getLeftMost(nodeToDelete.right);
231
+ const successor = this.getLeftMost(node => node, nodeToDelete.right);
244
232
  if (successor) {
245
233
  originalColor = successor.color;
246
234
  replacementNode = successor.right;
@@ -290,10 +278,6 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
290
278
  results.push({ deleted: nodeToDelete, needBalanced: undefined });
291
279
  return results;
292
280
  }
293
- /**
294
- * Time Complexity: O(1)
295
- * Space Complexity: O(1)
296
- */
297
281
  /**
298
282
  * Time Complexity: O(1)
299
283
  * Space Complexity: O(1)
@@ -305,10 +289,6 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
305
289
  super.clear();
306
290
  this._count = 0;
307
291
  }
308
- /**
309
- * Time Complexity: O(n log n)
310
- * Space Complexity: O(log n)
311
- */
312
292
  /**
313
293
  * Time Complexity: O(n log n)
314
294
  * Space Complexity: O(log n)
@@ -358,10 +338,6 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
358
338
  return true;
359
339
  }
360
340
  }
361
- /**
362
- * Time complexity: O(n)
363
- * Space complexity: O(n)
364
- */
365
341
  /**
366
342
  * Time complexity: O(n)
367
343
  * Space complexity: O(n)
@@ -374,10 +350,6 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
374
350
  this.bfs(node => cloned.add(node.key, node.value, node.count));
375
351
  return cloned;
376
352
  }
377
- /**
378
- * Time Complexity: O(1)
379
- * Space Complexity: O(1)
380
- */
381
353
  /**
382
354
  * Time Complexity: O(1)
383
355
  * Space Complexity: O(1)
@@ -413,10 +385,6 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
413
385
  }
414
386
  return undefined;
415
387
  }
416
- /**
417
- * Time Complexity: O(1)
418
- * Space Complexity: O(1)
419
- */
420
388
  /**
421
389
  * Time Complexity: O(1)
422
390
  * Space Complexity: O(1)
@@ -65,10 +65,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
65
65
  abstract edgesOf(vertexOrKey: VO | VertexKey): EO[];
66
66
  abstract getNeighbors(vertexOrKey: VO | VertexKey): VO[];
67
67
  abstract getEndsOfEdge(edge: EO): [VO, VO] | undefined;
68
- /**
69
- * Time Complexity: O(1) - Constant time for Map lookup.
70
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
71
- */
72
68
  /**
73
69
  * Time Complexity: O(1) - Constant time for Map lookup.
74
70
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
@@ -80,10 +76,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
80
76
  * map. If the vertex does not exist, it returns `undefined`.
81
77
  */
82
78
  getVertex(vertexKey: VertexKey): VO | undefined;
83
- /**
84
- * Time Complexity: O(1) - Constant time for Map lookup.
85
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
86
- */
87
79
  /**
88
80
  * Time Complexity: O(1) - Constant time for Map lookup.
89
81
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
@@ -102,10 +94,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
102
94
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
103
95
  */
104
96
  abstract deleteVertex(vertexOrKey: VO | VertexKey): boolean;
105
- /**
106
- * Time Complexity: O(K), where K is the number of vertexMap to be removed.
107
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
108
- */
109
97
  /**
110
98
  * Time Complexity: O(K), where K is the number of vertexMap to be removed.
111
99
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
@@ -117,10 +105,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
117
105
  * were removed.
118
106
  */
119
107
  removeManyVertices(vertexMap: VO[] | VertexKey[]): boolean;
120
- /**
121
- * Time Complexity: O(1) - Depends on the implementation in the concrete class.
122
- * Space Complexity: O(1) - Depends on the implementation in the concrete class.
123
- */
124
108
  /**
125
109
  * Time Complexity: O(1) - Depends on the implementation in the concrete class.
126
110
  * Space Complexity: O(1) - Depends on the implementation in the concrete class.
@@ -135,10 +119,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
135
119
  hasEdge(v1: VertexKey | VO, v2: VertexKey | VO): boolean;
136
120
  addEdge(edge: EO): boolean;
137
121
  addEdge(src: VO | VertexKey, dest: VO | VertexKey, weight?: number, value?: E): boolean;
138
- /**
139
- * Time Complexity: O(1) - Constant time for Map and Edge operations.
140
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
141
- */
142
122
  /**
143
123
  * Time Complexity: O(1) - Constant time for Map and Edge operations.
144
124
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
@@ -154,10 +134,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
154
134
  * the weight of the edge and return true. If the edge does not exist, the function will return false.
155
135
  */
156
136
  setEdgeWeight(srcOrKey: VertexKey | VO, destOrKey: VertexKey | VO, weight: number): boolean;
157
- /**
158
- * Time Complexity: O(P), where P is the number of paths found (in the worst case, exploring all paths).
159
- * Space Complexity: O(P) - Linear space, where P is the number of paths found.
160
- */
161
137
  /**
162
138
  * Time Complexity: O(P), where P is the number of paths found (in the worst case, exploring all paths).
163
139
  * Space Complexity: O(P) - Linear space, where P is the number of paths found.
@@ -170,10 +146,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
170
146
  * @returns The function `getAllPathsBetween` returns an array of arrays of vertexMap (`VO[][]`).
171
147
  */
172
148
  getAllPathsBetween(v1: VO | VertexKey, v2: VO | VertexKey, limit?: number): VO[][];
173
- /**
174
- * Time Complexity: O(L), where L is the length of the path.
175
- * Space Complexity: O(1) - Constant space.
176
- */
177
149
  /**
178
150
  * Time Complexity: O(L), where L is the length of the path.
179
151
  * Space Complexity: O(1) - Constant space.
@@ -183,10 +155,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
183
155
  * @returns The function `getPathSumWeight` returns the sum of the weights of the edgeMap in the given path.
184
156
  */
185
157
  getPathSumWeight(path: VO[]): number;
186
- /**
187
- * Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
188
- * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
189
- */
190
158
  /**
191
159
  * Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
192
160
  * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
@@ -205,10 +173,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
205
173
  * minimum number of
206
174
  */
207
175
  getMinCostBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean): number | undefined;
208
- /**
209
- * Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
210
- * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
211
- */
212
176
  /**
213
177
  * Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
214
178
  * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
@@ -229,13 +193,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
229
193
  * two vertexMap (`v1` and `v2`). If there is no path between the vertexMap, it returns `undefined`.
230
194
  */
231
195
  getMinPathBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean, isDFS?: boolean): VO[] | undefined;
232
- /**
233
- * Dijkstra algorithm time: O(VE) space: O(VO + EO)
234
- */
235
- /**
236
- * Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization).
237
- * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
238
- */
239
196
  /**
240
197
  * Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization).
241
198
  * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
@@ -256,18 +213,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
256
213
  * @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<VO>`.
257
214
  */
258
215
  dijkstraWithoutHeap(src: VO | VertexKey, dest?: VO | VertexKey | undefined, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<VO>;
259
- /**
260
- * Dijkstra algorithm time: O(logVE) space: O(VO + EO)
261
- *
262
- * 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.
263
- * 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.
264
- * 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.
265
- *
266
- */
267
- /**
268
- * Time Complexity: O((V + E) * log(V)) - Depends on the implementation (using a binary heap).
269
- * Space Complexity: O(V + E) - Depends on the implementation (using a binary heap).
270
- */
271
216
  /**
272
217
  * Time Complexity: O((V + E) * log(V)) - Depends on the implementation (using a binary heap).
273
218
  * Space Complexity: O(V + E) - Depends on the implementation (using a binary heap).
@@ -289,11 +234,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
289
234
  * @returns The function `dijkstra` returns an object of type `DijkstraResult<VO>`.
290
235
  */
291
236
  dijkstra(src: VO | VertexKey, dest?: VO | VertexKey | undefined, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<VO>;
292
- /**
293
- * Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
294
- * Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
295
- * one to rest pairs
296
- */
297
237
  /**
298
238
  * Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
299
239
  * Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
@@ -333,13 +273,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
333
273
  * The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edgeMap for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edgeMap, the Bellman-Ford algorithm is more flexible in some scenarios.
334
274
  * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
335
275
  */
336
- /**
337
- * Time Complexity: O(V^3) - Cubic time (Floyd-Warshall algorithm).
338
- * Space Complexity: O(V^2) - Quadratic space (Floyd-Warshall algorithm).
339
- * Not support graph with negative weight cycle
340
- * all pairs
341
- * 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.
342
- */
343
276
  /**
344
277
  * Time Complexity: O(V^3) - Cubic time (Floyd-Warshall algorithm).
345
278
  * Space Complexity: O(V^2) - Quadratic space (Floyd-Warshall algorithm).
@@ -363,10 +296,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
363
296
  * O(V+C)
364
297
  */
365
298
  getCycles(isInclude2Cycle?: boolean): VertexKey[][];
366
- /**
367
- * Time Complexity: O(n)
368
- * Space Complexity: O(n)
369
- */
370
299
  /**
371
300
  * Time Complexity: O(n)
372
301
  * Space Complexity: O(n)
@@ -384,10 +313,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
384
313
  * that satisfy the given predicate function.
385
314
  */
386
315
  filter(predicate: EntryCallback<VertexKey, V | undefined, boolean>, thisArg?: any): [VertexKey, V | undefined][];
387
- /**
388
- * Time Complexity: O(n)
389
- * Space Complexity: O(n)
390
- */
391
316
  /**
392
317
  * Time Complexity: O(n)
393
318
  * Space Complexity: O(n)
@@ -53,10 +53,6 @@ class AbstractGraph extends base_1.IterableEntryBase {
53
53
  get size() {
54
54
  return this._vertexMap.size;
55
55
  }
56
- /**
57
- * Time Complexity: O(1) - Constant time for Map lookup.
58
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
59
- */
60
56
  /**
61
57
  * Time Complexity: O(1) - Constant time for Map lookup.
62
58
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
@@ -70,10 +66,6 @@ class AbstractGraph extends base_1.IterableEntryBase {
70
66
  getVertex(vertexKey) {
71
67
  return this._vertexMap.get(vertexKey) || undefined;
72
68
  }
73
- /**
74
- * Time Complexity: O(1) - Constant time for Map lookup.
75
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
76
- */
77
69
  /**
78
70
  * Time Complexity: O(1) - Constant time for Map lookup.
79
71
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
@@ -103,10 +95,6 @@ class AbstractGraph extends base_1.IterableEntryBase {
103
95
  const potentialKeyType = typeof potentialKey;
104
96
  return potentialKeyType === 'string' || potentialKeyType === 'number';
105
97
  }
106
- /**
107
- * Time Complexity: O(K), where K is the number of vertexMap to be removed.
108
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
109
- */
110
98
  /**
111
99
  * Time Complexity: O(K), where K is the number of vertexMap to be removed.
112
100
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
@@ -124,10 +112,6 @@ class AbstractGraph extends base_1.IterableEntryBase {
124
112
  }
125
113
  return removed.length > 0;
126
114
  }
127
- /**
128
- * Time Complexity: O(1) - Depends on the implementation in the concrete class.
129
- * Space Complexity: O(1) - Depends on the implementation in the concrete class.
130
- */
131
115
  /**
132
116
  * Time Complexity: O(1) - Depends on the implementation in the concrete class.
133
117
  * Space Complexity: O(1) - Depends on the implementation in the concrete class.
@@ -167,10 +151,6 @@ class AbstractGraph extends base_1.IterableEntryBase {
167
151
  }
168
152
  }
169
153
  }
170
- /**
171
- * Time Complexity: O(1) - Constant time for Map and Edge operations.
172
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
173
- */
174
154
  /**
175
155
  * Time Complexity: O(1) - Constant time for Map and Edge operations.
176
156
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
@@ -195,10 +175,6 @@ class AbstractGraph extends base_1.IterableEntryBase {
195
175
  return false;
196
176
  }
197
177
  }
198
- /**
199
- * Time Complexity: O(P), where P is the number of paths found (in the worst case, exploring all paths).
200
- * Space Complexity: O(P) - Linear space, where P is the number of paths found.
201
- */
202
178
  /**
203
179
  * Time Complexity: O(P), where P is the number of paths found (in the worst case, exploring all paths).
204
180
  * Space Complexity: O(P) - Linear space, where P is the number of paths found.
@@ -236,10 +212,6 @@ class AbstractGraph extends base_1.IterableEntryBase {
236
212
  }
237
213
  return paths;
238
214
  }
239
- /**
240
- * Time Complexity: O(L), where L is the length of the path.
241
- * Space Complexity: O(1) - Constant space.
242
- */
243
215
  /**
244
216
  * Time Complexity: O(L), where L is the length of the path.
245
217
  * Space Complexity: O(1) - Constant space.
@@ -256,10 +228,6 @@ class AbstractGraph extends base_1.IterableEntryBase {
256
228
  }
257
229
  return sum;
258
230
  }
259
- /**
260
- * Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
261
- * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
262
- */
263
231
  /**
264
232
  * Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
265
233
  * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
@@ -321,10 +289,6 @@ class AbstractGraph extends base_1.IterableEntryBase {
321
289
  return undefined;
322
290
  }
323
291
  }
324
- /**
325
- * Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
326
- * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
327
- */
328
292
  /**
329
293
  * Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
330
294
  * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
@@ -395,13 +359,6 @@ class AbstractGraph extends base_1.IterableEntryBase {
395
359
  return minPath;
396
360
  }
397
361
  }
398
- /**
399
- * Dijkstra algorithm time: O(VE) space: O(VO + EO)
400
- */
401
- /**
402
- * Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization).
403
- * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
404
- */
405
362
  /**
406
363
  * Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization).
407
364
  * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
@@ -517,18 +474,6 @@ class AbstractGraph extends base_1.IterableEntryBase {
517
474
  genPaths && getPaths(minDest);
518
475
  return { distMap, preMap, seen, paths, minDist, minPath };
519
476
  }
520
- /**
521
- * Dijkstra algorithm time: O(logVE) space: O(VO + EO)
522
- *
523
- * 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.
524
- * 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.
525
- * 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.
526
- *
527
- */
528
- /**
529
- * Time Complexity: O((V + E) * log(V)) - Depends on the implementation (using a binary heap).
530
- * Space Complexity: O(V + E) - Depends on the implementation (using a binary heap).
531
- */
532
477
  /**
533
478
  * Time Complexity: O((V + E) * log(V)) - Depends on the implementation (using a binary heap).
534
479
  * Space Complexity: O(V + E) - Depends on the implementation (using a binary heap).
@@ -645,11 +590,6 @@ class AbstractGraph extends base_1.IterableEntryBase {
645
590
  }
646
591
  return { distMap, preMap, seen, paths, minDist, minPath };
647
592
  }
648
- /**
649
- * Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
650
- * Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
651
- * one to rest pairs
652
- */
653
593
  /**
654
594
  * Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
655
595
  * Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
@@ -766,13 +706,6 @@ class AbstractGraph extends base_1.IterableEntryBase {
766
706
  * The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edgeMap for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edgeMap, the Bellman-Ford algorithm is more flexible in some scenarios.
767
707
  * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
768
708
  */
769
- /**
770
- * Time Complexity: O(V^3) - Cubic time (Floyd-Warshall algorithm).
771
- * Space Complexity: O(V^2) - Quadratic space (Floyd-Warshall algorithm).
772
- * Not support graph with negative weight cycle
773
- * all pairs
774
- * 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.
775
- */
776
709
  /**
777
710
  * Time Complexity: O(V^3) - Cubic time (Floyd-Warshall algorithm).
778
711
  * Space Complexity: O(V^2) - Quadratic space (Floyd-Warshall algorithm).
@@ -857,10 +790,6 @@ class AbstractGraph extends base_1.IterableEntryBase {
857
790
  // Convert the unique cycles back to an array
858
791
  return [...uniqueCycles].map(cycleString => cycleString[1]);
859
792
  }
860
- /**
861
- * Time Complexity: O(n)
862
- * Space Complexity: O(n)
863
- */
864
793
  /**
865
794
  * Time Complexity: O(n)
866
795
  * Space Complexity: O(n)
@@ -888,10 +817,6 @@ class AbstractGraph extends base_1.IterableEntryBase {
888
817
  }
889
818
  return filtered;
890
819
  }
891
- /**
892
- * Time Complexity: O(n)
893
- * Space Complexity: O(n)
894
- */
895
820
  /**
896
821
  * Time Complexity: O(n)
897
822
  * Space Complexity: O(n)