mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-12-26 23:21:18 +08:00
Add Tarjan's algorithm.
This commit is contained in:
parent
1dd480b906
commit
670ec093f4
@ -65,7 +65,13 @@ export default function articulationPoints(graph) {
|
|||||||
// Update the low time with the smallest time of adjacent vertices.
|
// Update the low time with the smallest time of adjacent vertices.
|
||||||
// Get minimum low discovery time from all neighbors.
|
// Get minimum low discovery time from all neighbors.
|
||||||
/** @param {GraphVertex} neighbor */
|
/** @param {GraphVertex} neighbor */
|
||||||
visitedSet[currentVertex.getKey()].lowDiscoveryTime = currentVertex.getNeighbors().reduce(
|
visitedSet[currentVertex.getKey()].lowDiscoveryTime = currentVertex.getNeighbors()
|
||||||
|
.filter(earlyNeighbor => earlyNeighbor.getKey() !== previousVertex.getKey())
|
||||||
|
/**
|
||||||
|
* @param {number} lowestDiscoveryTime
|
||||||
|
* @param {GraphVertex} neighbor
|
||||||
|
*/
|
||||||
|
.reduce(
|
||||||
(lowestDiscoveryTime, neighbor) => {
|
(lowestDiscoveryTime, neighbor) => {
|
||||||
const neighborLowTime = visitedSet[neighbor.getKey()].lowDiscoveryTime;
|
const neighborLowTime = visitedSet[neighbor.getKey()].lowDiscoveryTime;
|
||||||
return neighborLowTime < lowestDiscoveryTime ? neighborLowTime : lowestDiscoveryTime;
|
return neighborLowTime < lowestDiscoveryTime ? neighborLowTime : lowestDiscoveryTime;
|
||||||
|
Loading…
Reference in New Issue
Block a user