stack-typed 1.48.4 → 1.48.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-base.d.ts +6 -6
- package/dist/data-structures/base/iterable-base.js +3 -3
- package/dist/data-structures/binary-tree/avl-tree.d.ts +5 -3
- package/dist/data-structures/binary-tree/avl-tree.js +6 -4
- package/dist/data-structures/binary-tree/binary-tree.d.ts +18 -15
- package/dist/data-structures/binary-tree/binary-tree.js +16 -13
- package/dist/data-structures/binary-tree/bst.d.ts +15 -11
- package/dist/data-structures/binary-tree/bst.js +17 -13
- package/dist/data-structures/binary-tree/rb-tree.d.ts +19 -13
- package/dist/data-structures/binary-tree/rb-tree.js +20 -14
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +21 -14
- package/dist/data-structures/binary-tree/tree-multimap.js +25 -18
- package/dist/data-structures/graph/abstract-graph.d.ts +52 -52
- package/dist/data-structures/graph/abstract-graph.js +78 -78
- package/dist/data-structures/graph/directed-graph.d.ts +47 -47
- package/dist/data-structures/graph/directed-graph.js +56 -56
- package/dist/data-structures/graph/map-graph.d.ts +5 -5
- package/dist/data-structures/graph/map-graph.js +8 -8
- package/dist/data-structures/graph/undirected-graph.d.ts +29 -29
- package/dist/data-structures/graph/undirected-graph.js +57 -57
- package/dist/data-structures/hash/hash-map.d.ts +8 -8
- package/dist/data-structures/hash/hash-map.js +2 -2
- package/dist/interfaces/binary-tree.d.ts +1 -1
- package/dist/types/data-structures/base/base.d.ts +3 -3
- package/package.json +2 -2
- package/src/data-structures/base/iterable-base.ts +6 -6
- package/src/data-structures/binary-tree/avl-tree.ts +8 -5
- package/src/data-structures/binary-tree/binary-tree.ts +23 -19
- package/src/data-structures/binary-tree/bst.ts +19 -14
- package/src/data-structures/binary-tree/rb-tree.ts +20 -14
- package/src/data-structures/binary-tree/tree-multimap.ts +27 -19
- package/src/data-structures/graph/abstract-graph.ts +82 -82
- package/src/data-structures/graph/directed-graph.ts +56 -56
- package/src/data-structures/graph/map-graph.ts +8 -8
- package/src/data-structures/graph/undirected-graph.ts +59 -59
- package/src/data-structures/hash/hash-map.ts +8 -8
- package/src/interfaces/binary-tree.ts +1 -1
- package/src/types/data-structures/base/base.ts +3 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DijkstraResult, VertexKey } from '../../types';
|
|
2
|
-
import {
|
|
2
|
+
import { EntryCallback } from "../../types";
|
|
3
3
|
import { IGraph } from '../../interfaces';
|
|
4
|
-
import {
|
|
4
|
+
import { IterableEntryBase } from "../base";
|
|
5
5
|
export declare abstract class AbstractVertex<V = any> {
|
|
6
6
|
key: VertexKey;
|
|
7
7
|
value: V | undefined;
|
|
@@ -30,10 +30,10 @@ export declare abstract class AbstractEdge<E = any> {
|
|
|
30
30
|
protected _hashCode: string;
|
|
31
31
|
get hashCode(): string;
|
|
32
32
|
}
|
|
33
|
-
export declare abstract class AbstractGraph<V = any, E = any, VO extends AbstractVertex<V> = AbstractVertex<V>, EO extends AbstractEdge<E> = AbstractEdge<E>> extends
|
|
33
|
+
export declare abstract class AbstractGraph<V = any, E = any, VO extends AbstractVertex<V> = AbstractVertex<V>, EO extends AbstractEdge<E> = AbstractEdge<E>> extends IterableEntryBase<VertexKey, V | undefined> implements IGraph<V, E, VO, EO> {
|
|
34
34
|
constructor();
|
|
35
|
-
protected
|
|
36
|
-
get
|
|
35
|
+
protected _vertexMap: Map<VertexKey, VO>;
|
|
36
|
+
get vertexMap(): Map<VertexKey, VO>;
|
|
37
37
|
/**
|
|
38
38
|
* In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
|
|
39
39
|
* This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
|
|
@@ -67,8 +67,8 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
67
67
|
*
|
|
68
68
|
* The function "getVertex" returns the vertex with the specified ID or undefined if it doesn't exist.
|
|
69
69
|
* @param {VertexKey} vertexKey - The `vertexKey` parameter is the identifier of the vertex that you want to retrieve from
|
|
70
|
-
* the `
|
|
71
|
-
* @returns The method `getVertex` returns the vertex with the specified `vertexKey` if it exists in the `
|
|
70
|
+
* the `_vertexMap` map.
|
|
71
|
+
* @returns The method `getVertex` returns the vertex with the specified `vertexKey` if it exists in the `_vertexMap`
|
|
72
72
|
* map. If the vertex does not exist, it returns `undefined`.
|
|
73
73
|
*/
|
|
74
74
|
getVertex(vertexKey: VertexKey): VO | undefined;
|
|
@@ -104,20 +104,20 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
104
104
|
*/
|
|
105
105
|
deleteVertex(vertexOrKey: VO | VertexKey): boolean;
|
|
106
106
|
/**
|
|
107
|
-
* Time Complexity: O(K), where K is the number of
|
|
107
|
+
* Time Complexity: O(K), where K is the number of vertexMap to be removed.
|
|
108
108
|
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
109
109
|
*/
|
|
110
110
|
/**
|
|
111
|
-
* Time Complexity: O(K), where K is the number of
|
|
111
|
+
* Time Complexity: O(K), where K is the number of vertexMap to be removed.
|
|
112
112
|
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
113
113
|
*
|
|
114
|
-
* The function removes all
|
|
115
|
-
* @param {VO[] | VertexKey[]}
|
|
114
|
+
* The function removes all vertexMap from a graph and returns a boolean indicating if any vertexMap were removed.
|
|
115
|
+
* @param {VO[] | VertexKey[]} vertexMap - The `vertexMap` parameter can be either an array of vertexMap (`VO[]`) or an array
|
|
116
116
|
* of vertex IDs (`VertexKey[]`).
|
|
117
|
-
* @returns a boolean value. It returns true if at least one vertex was successfully removed, and false if no
|
|
117
|
+
* @returns a boolean value. It returns true if at least one vertex was successfully removed, and false if no vertexMap
|
|
118
118
|
* were removed.
|
|
119
119
|
*/
|
|
120
|
-
removeManyVertices(
|
|
120
|
+
removeManyVertices(vertexMap: VO[] | VertexKey[]): boolean;
|
|
121
121
|
/**
|
|
122
122
|
* Time Complexity: O(1) - Depends on the implementation in the concrete class.
|
|
123
123
|
* Space Complexity: O(1) - Depends on the implementation in the concrete class.
|
|
@@ -126,7 +126,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
126
126
|
* Time Complexity: O(1) - Depends on the implementation in the concrete class.
|
|
127
127
|
* Space Complexity: O(1) - Depends on the implementation in the concrete class.
|
|
128
128
|
*
|
|
129
|
-
* The function checks if there is an edge between two
|
|
129
|
+
* The function checks if there is an edge between two vertexMap and returns a boolean value indicating the result.
|
|
130
130
|
* @param {VertexKey | VO} v1 - The parameter v1 can be either a VertexKey or a VO. A VertexKey represents the unique
|
|
131
131
|
* identifier of a vertex in a graph, while VO represents the type of the vertex object itself.
|
|
132
132
|
* @param {VertexKey | VO} v2 - The parameter `v2` represents the second vertex in the edge. It can be either a
|
|
@@ -144,14 +144,14 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
144
144
|
* Time Complexity: O(1) - Constant time for Map and Edge operations.
|
|
145
145
|
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
146
146
|
*
|
|
147
|
-
* The function sets the weight of an edge between two
|
|
147
|
+
* The function sets the weight of an edge between two vertexMap in a graph.
|
|
148
148
|
* @param {VertexKey | VO} srcOrKey - The `srcOrKey` parameter can be either a `VertexKey` or a `VO` object. It represents
|
|
149
149
|
* the source vertex of the edge.
|
|
150
150
|
* @param {VertexKey | VO} destOrKey - The `destOrKey` parameter represents the destination vertex of the edge. It can be
|
|
151
151
|
* either a `VertexKey` or a vertex object `VO`.
|
|
152
152
|
* @param {number} weight - The weight parameter represents the weight of the edge between the source vertex (srcOrKey)
|
|
153
153
|
* and the destination vertex (destOrKey).
|
|
154
|
-
* @returns a boolean value. If the edge exists between the source and destination
|
|
154
|
+
* @returns a boolean value. If the edge exists between the source and destination vertexMap, the function will update
|
|
155
155
|
* the weight of the edge and return true. If the edge does not exist, the function will return false.
|
|
156
156
|
*/
|
|
157
157
|
setEdgeWeight(srcOrKey: VertexKey | VO, destOrKey: VertexKey | VO, weight: number): boolean;
|
|
@@ -163,12 +163,12 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
163
163
|
* Time Complexity: O(P), where P is the number of paths found (in the worst case, exploring all paths).
|
|
164
164
|
* Space Complexity: O(P) - Linear space, where P is the number of paths found.
|
|
165
165
|
*
|
|
166
|
-
* The function `getAllPathsBetween` finds all paths between two
|
|
166
|
+
* The function `getAllPathsBetween` finds all paths between two vertexMap in a graph using depth-first search.
|
|
167
167
|
* @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
|
|
168
168
|
* It is the starting vertex for finding paths.
|
|
169
169
|
* @param {VO | VertexKey} v2 - The parameter `v2` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
|
|
170
170
|
* @param limit - The count of limitation of result array.
|
|
171
|
-
* @returns The function `getAllPathsBetween` returns an array of arrays of
|
|
171
|
+
* @returns The function `getAllPathsBetween` returns an array of arrays of vertexMap (`VO[][]`).
|
|
172
172
|
*/
|
|
173
173
|
getAllPathsBetween(v1: VO | VertexKey, v2: VO | VertexKey, limit?: number): VO[][];
|
|
174
174
|
/**
|
|
@@ -180,8 +180,8 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
180
180
|
* Space Complexity: O(1) - Constant space.
|
|
181
181
|
*
|
|
182
182
|
* The function calculates the sum of weights along a given path.
|
|
183
|
-
* @param {VO[]} path - An array of
|
|
184
|
-
* @returns The function `getPathSumWeight` returns the sum of the weights of the
|
|
183
|
+
* @param {VO[]} path - An array of vertexMap (VO) representing a path in a graph.
|
|
184
|
+
* @returns The function `getPathSumWeight` returns the sum of the weights of the edgeMap in the given path.
|
|
185
185
|
*/
|
|
186
186
|
getPathSumWeight(path: VO[]): number;
|
|
187
187
|
/**
|
|
@@ -192,17 +192,17 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
192
192
|
* Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
|
|
193
193
|
* Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
|
|
194
194
|
*
|
|
195
|
-
* The function `getMinCostBetween` calculates the minimum cost between two
|
|
195
|
+
* The function `getMinCostBetween` calculates the minimum cost between two vertexMap in a graph, either based on edge
|
|
196
196
|
* weights or using a breadth-first search algorithm.
|
|
197
197
|
* @param {VO | VertexKey} v1 - The parameter `v1` represents the starting vertex or its ID.
|
|
198
198
|
* @param {VO | VertexKey} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex to which
|
|
199
199
|
* you want to find the minimum cost or weight from the source vertex `v1`.
|
|
200
|
-
* @param {boolean} [isWeight] - isWeight is an optional parameter that indicates whether the graph
|
|
200
|
+
* @param {boolean} [isWeight] - isWeight is an optional parameter that indicates whether the graph edgeMap have weights.
|
|
201
201
|
* If isWeight is set to true, the function will calculate the minimum cost between v1 and v2 based on the weights of
|
|
202
|
-
* the
|
|
203
|
-
* @returns The function `getMinCostBetween` returns a number representing the minimum cost between two
|
|
202
|
+
* the edgeMap. If isWeight is set to false or not provided, the function will calculate the
|
|
203
|
+
* @returns The function `getMinCostBetween` returns a number representing the minimum cost between two vertexMap (`v1`
|
|
204
204
|
* and `v2`). If the `isWeight` parameter is `true`, it calculates the minimum weight among all paths between the
|
|
205
|
-
*
|
|
205
|
+
* vertexMap. If `isWeight` is `false` or not provided, it uses a breadth-first search (BFS) algorithm to calculate the
|
|
206
206
|
* minimum number of
|
|
207
207
|
*/
|
|
208
208
|
getMinCostBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean): number | undefined;
|
|
@@ -214,20 +214,20 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
214
214
|
* Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
|
|
215
215
|
* Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
|
|
216
216
|
*
|
|
217
|
-
* The function `getMinPathBetween` returns the minimum path between two
|
|
217
|
+
* The function `getMinPathBetween` returns the minimum path between two vertexMap in a graph, either based on weight or
|
|
218
218
|
* using a breadth-first search algorithm.
|
|
219
219
|
* @param {VO | VertexKey} v1 - The parameter `v1` represents the starting vertex of the path. It can be either a vertex
|
|
220
220
|
* object (`VO`) or a vertex ID (`VertexKey`).
|
|
221
221
|
* @param {VO | VertexKey} v2 - VO | VertexKey - The second vertex or vertex ID between which we want to find the minimum
|
|
222
222
|
* path.
|
|
223
|
-
* @param {boolean} [isWeight] - A boolean flag indicating whether to consider the weight of
|
|
223
|
+
* @param {boolean} [isWeight] - A boolean flag indicating whether to consider the weight of edgeMap in finding the
|
|
224
224
|
* minimum path. If set to true, the function will use Dijkstra's algorithm to find the minimum weighted path. If set
|
|
225
225
|
* to false, the function will use breadth-first search (BFS) to find the minimum path.
|
|
226
226
|
* @param isDFS - If set to true, it enforces the use of getAllPathsBetween to first obtain all possible paths,
|
|
227
227
|
* followed by iterative computation of the shortest path. This approach may result in exponential time complexity,
|
|
228
228
|
* so the default method is to use the Dijkstra algorithm to obtain the shortest weighted path.
|
|
229
|
-
* @returns The function `getMinPathBetween` returns an array of
|
|
230
|
-
* two
|
|
229
|
+
* @returns The function `getMinPathBetween` returns an array of vertexMap (`VO[]`) representing the minimum path between
|
|
230
|
+
* two vertexMap (`v1` and `v2`). If there is no path between the vertexMap, it returns `undefined`.
|
|
231
231
|
*/
|
|
232
232
|
getMinPathBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean, isDFS?: boolean): VO[] | undefined;
|
|
233
233
|
/**
|
|
@@ -242,7 +242,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
242
242
|
* Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization).
|
|
243
243
|
* Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
|
|
244
244
|
*
|
|
245
|
-
* The function `dijkstraWithoutHeap` implements Dijkstra's algorithm to find the shortest path between two
|
|
245
|
+
* The function `dijkstraWithoutHeap` implements Dijkstra's algorithm to find the shortest path between two vertexMap in
|
|
246
246
|
* a graph without using a heap data structure.
|
|
247
247
|
* @param {VO | VertexKey} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
|
|
248
248
|
* vertex object or a vertex ID.
|
|
@@ -254,7 +254,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
254
254
|
* `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
|
|
255
255
|
* @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
|
|
256
256
|
* paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
|
|
257
|
-
* shortest paths from the source vertex to all other
|
|
257
|
+
* shortest paths from the source vertex to all other vertexMap in the graph. If `genPaths
|
|
258
258
|
* @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<VO>`.
|
|
259
259
|
*/
|
|
260
260
|
dijkstraWithoutHeap(src: VO | VertexKey, dest?: VO | VertexKey | undefined, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<VO>;
|
|
@@ -262,7 +262,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
262
262
|
* Dijkstra algorithm time: O(logVE) space: O(VO + EO)
|
|
263
263
|
*
|
|
264
264
|
* 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.
|
|
265
|
-
* 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
|
|
265
|
+
* 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.
|
|
266
266
|
* 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.
|
|
267
267
|
*
|
|
268
268
|
* /
|
|
@@ -282,13 +282,13 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
282
282
|
* start. It can be either a vertex object or a vertex ID.
|
|
283
283
|
* @param {VO | VertexKey | undefined} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
|
|
284
284
|
* vertex to which the shortest path is calculated from the source vertex. If no destination is provided, the algorithm
|
|
285
|
-
* will calculate the shortest paths to all other
|
|
285
|
+
* will calculate the shortest paths to all other vertexMap from the source vertex.
|
|
286
286
|
* @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
|
|
287
287
|
* distance from the source vertex to the destination vertex should be calculated and returned in the result. If
|
|
288
288
|
* `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
|
|
289
289
|
* @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
|
|
290
290
|
* paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
|
|
291
|
-
* shortest paths from the source vertex to all other
|
|
291
|
+
* shortest paths from the source vertex to all other vertexMap in the graph. If `genPaths
|
|
292
292
|
* @returns The function `dijkstra` returns an object of type `DijkstraResult<VO>`.
|
|
293
293
|
*/
|
|
294
294
|
dijkstra(src: VO | VertexKey, dest?: VO | VertexKey | undefined, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<VO>;
|
|
@@ -303,16 +303,16 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
303
303
|
* Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
|
|
304
304
|
*
|
|
305
305
|
* one to rest pairs
|
|
306
|
-
* 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
|
|
306
|
+
* 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.
|
|
307
307
|
* The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
|
|
308
|
-
* all other
|
|
308
|
+
* all other vertexMap in a graph, and optionally detects negative cycles and generates the minimum path.
|
|
309
309
|
* @param {VO | VertexKey} src - The `src` parameter is the source vertex from which the Bellman-Ford algorithm will
|
|
310
310
|
* start calculating the shortest paths. It can be either a vertex object or a vertex ID.
|
|
311
311
|
* @param {boolean} [scanNegativeCycle] - A boolean flag indicating whether to scan for negative cycles in the graph.
|
|
312
312
|
* @param {boolean} [getMin] - The `getMin` parameter is a boolean flag that determines whether the algorithm should
|
|
313
|
-
* calculate the minimum distance from the source vertex to all other
|
|
313
|
+
* calculate the minimum distance from the source vertex to all other vertexMap in the graph. If `getMin` is set to
|
|
314
314
|
* `true`, the algorithm will find the minimum distance and update the `min` variable with the minimum
|
|
315
|
-
* @param {boolean} [genPath] - A boolean flag indicating whether to generate paths for all
|
|
315
|
+
* @param {boolean} [genPath] - A boolean flag indicating whether to generate paths for all vertexMap from the source
|
|
316
316
|
* vertex.
|
|
317
317
|
* @returns The function `bellmanFord` returns an object with the following properties:
|
|
318
318
|
*/
|
|
@@ -335,7 +335,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
335
335
|
/**
|
|
336
336
|
* BellmanFord time:O(VE) space:O(VO)
|
|
337
337
|
* one to rest pairs
|
|
338
|
-
* 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
|
|
338
|
+
* 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.
|
|
339
339
|
* The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
|
|
340
340
|
*/
|
|
341
341
|
/**
|
|
@@ -343,7 +343,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
343
343
|
* Space Complexity: O(V^2) - Quadratic space (Floyd-Warshall algorithm).
|
|
344
344
|
* Not support graph with negative weight cycle
|
|
345
345
|
* all pairs
|
|
346
|
-
* 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
|
|
346
|
+
* 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.
|
|
347
347
|
* /
|
|
348
348
|
|
|
349
349
|
/**
|
|
@@ -352,13 +352,13 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
352
352
|
*
|
|
353
353
|
* Not support graph with negative weight cycle
|
|
354
354
|
* all pairs
|
|
355
|
-
* 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
|
|
356
|
-
* The function implements the Floyd-Warshall algorithm to find the shortest path between all pairs of
|
|
355
|
+
* 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.
|
|
356
|
+
* The function implements the Floyd-Warshall algorithm to find the shortest path between all pairs of vertexMap in a
|
|
357
357
|
* graph.
|
|
358
358
|
* @returns The function `floydWarshall()` returns an object with two properties: `costs` and `predecessor`. The `costs`
|
|
359
|
-
* property is a 2D array of numbers representing the shortest path costs between
|
|
360
|
-
* `predecessor` property is a 2D array of
|
|
361
|
-
* path between
|
|
359
|
+
* property is a 2D array of numbers representing the shortest path costs between vertexMap in a graph. The
|
|
360
|
+
* `predecessor` property is a 2D array of vertexMap (or `undefined`) representing the predecessor vertexMap in the shortest
|
|
361
|
+
* path between vertexMap in the
|
|
362
362
|
*/
|
|
363
363
|
floydWarshall(): {
|
|
364
364
|
costs: number[][];
|
|
@@ -369,7 +369,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
369
369
|
* Space Complexity: O(V) - Linear space (Tarjan's algorithm).
|
|
370
370
|
* Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
|
|
371
371
|
* Tarjan can find cycles in directed or undirected graph
|
|
372
|
-
* Tarjan can find the articulation points and bridges(critical
|
|
372
|
+
* Tarjan can find the articulation points and bridges(critical edgeMap) of undirected graphs in linear time,
|
|
373
373
|
* Tarjan solve the bi-connected components of undirected graphs;
|
|
374
374
|
* Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
|
|
375
375
|
* /
|
|
@@ -380,22 +380,22 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
380
380
|
*
|
|
381
381
|
* Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
|
|
382
382
|
* Tarjan can find cycles in directed or undirected graph
|
|
383
|
-
* Tarjan can find the articulation points and bridges(critical
|
|
383
|
+
* Tarjan can find the articulation points and bridges(critical edgeMap) of undirected graphs in linear time,
|
|
384
384
|
* Tarjan solve the bi-connected components of undirected graphs;
|
|
385
385
|
* Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
|
|
386
386
|
* The `tarjan` function is used to perform various graph analysis tasks such as finding articulation points, bridges,
|
|
387
387
|
* strongly connected components (SCCs), and cycles in a graph.
|
|
388
388
|
* @param {boolean} [needCutVertexes] - A boolean value indicating whether or not to calculate and return the
|
|
389
|
-
* articulation points in the graph. Articulation points are the
|
|
389
|
+
* articulation points in the graph. Articulation points are the vertexMap in a graph whose removal would increase the
|
|
390
390
|
* number of connected components in the graph.
|
|
391
391
|
* @param {boolean} [needBridges] - A boolean flag indicating whether the algorithm should find and return the bridges
|
|
392
|
-
* (
|
|
392
|
+
* (edgeMap whose removal would increase the number of connected components in the graph).
|
|
393
393
|
* @param {boolean} [needSCCs] - A boolean value indicating whether the Strongly Connected Components (SCCs) of the
|
|
394
394
|
* graph are needed. If set to true, the function will calculate and return the SCCs of the graph. If set to false, the
|
|
395
395
|
* SCCs will not be calculated or returned.
|
|
396
396
|
* @param {boolean} [needCycles] - A boolean flag indicating whether the algorithm should find cycles in the graph. If
|
|
397
397
|
* set to true, the algorithm will return a map of cycles, where the keys are the low values of the SCCs and the values
|
|
398
|
-
* are arrays of
|
|
398
|
+
* are arrays of vertexMap that form cycles within the SCCs.
|
|
399
399
|
* @returns The function `tarjan` returns an object with the following properties:
|
|
400
400
|
*/
|
|
401
401
|
tarjan(needCutVertexes?: boolean, needBridges?: boolean, needSCCs?: boolean, needCycles?: boolean): {
|
|
@@ -467,7 +467,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
467
467
|
* @returns The `filter` method returns an array of key-value pairs `[VertexKey, V | undefined][]`
|
|
468
468
|
* that satisfy the given predicate function.
|
|
469
469
|
*/
|
|
470
|
-
filter(predicate:
|
|
470
|
+
filter(predicate: EntryCallback<VertexKey, V | undefined, boolean>, thisArg?: any): [VertexKey, V | undefined][];
|
|
471
471
|
/**
|
|
472
472
|
* Time Complexity: O(n)
|
|
473
473
|
* Space Complexity: O(n)
|
|
@@ -485,7 +485,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
485
485
|
* used as the `this` value when calling the callback function. If `thisArg` is not provided, `
|
|
486
486
|
* @returns The `map` function is returning an array of type `T[]`.
|
|
487
487
|
*/
|
|
488
|
-
map<T>(callback:
|
|
488
|
+
map<T>(callback: EntryCallback<VertexKey, V | undefined, T>, thisArg?: any): T[];
|
|
489
489
|
protected _getIterator(): IterableIterator<[VertexKey, V | undefined]>;
|
|
490
490
|
protected abstract _addEdgeOnly(edge: EO): boolean;
|
|
491
491
|
protected _addVertexOnly(newVertex: VO): boolean;
|