mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-12-25 22:46:20 +08:00
Add Tarjan's algorithm.
This commit is contained in:
parent
1dd480b906
commit
670ec093f4
@ -65,13 +65,19 @@ export default function articulationPoints(graph) {
|
||||
// Update the low time with the smallest time of adjacent vertices.
|
||||
// Get minimum low discovery time from all neighbors.
|
||||
/** @param {GraphVertex} neighbor */
|
||||
visitedSet[currentVertex.getKey()].lowDiscoveryTime = currentVertex.getNeighbors().reduce(
|
||||
(lowestDiscoveryTime, neighbor) => {
|
||||
const neighborLowTime = visitedSet[neighbor.getKey()].lowDiscoveryTime;
|
||||
return neighborLowTime < lowestDiscoveryTime ? neighborLowTime : lowestDiscoveryTime;
|
||||
},
|
||||
visitedSet[currentVertex.getKey()].lowDiscoveryTime,
|
||||
);
|
||||
visitedSet[currentVertex.getKey()].lowDiscoveryTime = currentVertex.getNeighbors()
|
||||
.filter(earlyNeighbor => earlyNeighbor.getKey() !== previousVertex.getKey())
|
||||
/**
|
||||
* @param {number} lowestDiscoveryTime
|
||||
* @param {GraphVertex} neighbor
|
||||
*/
|
||||
.reduce(
|
||||
(lowestDiscoveryTime, neighbor) => {
|
||||
const neighborLowTime = visitedSet[neighbor.getKey()].lowDiscoveryTime;
|
||||
return neighborLowTime < lowestDiscoveryTime ? neighborLowTime : lowestDiscoveryTime;
|
||||
},
|
||||
visitedSet[currentVertex.getKey()].lowDiscoveryTime,
|
||||
);
|
||||
|
||||
// Detect whether previous vertex is articulation point or not.
|
||||
// To do so we need to check two [OR] conditions:
|
||||
|
Loading…
Reference in New Issue
Block a user