Working with Graphs & Trees
What is the first phase of which graph algorithm?
function stronglyConnected(graph) {
const visited = new Set();
const stack = [];
function dfs1(vertex) {
visited.add(vertex);
for (let neighbor of graph[vertex]) {
if (!visited.has(neighbor)) dfs1(neighbor);
}
stack.push(vertex);
}
// First DFS to fill stack
for (let vertex in graph) {
if (!visited.has(vertex)) dfs1(vertex);
}
}