MCPcopy
hub / github.com/TheAlgorithms/TypeScript / kosajaru

Function kosajaru

graph/kosajaru.ts:64–84  ·  view source on GitHub ↗
(graph: number[][])

Source from the content-addressed store, hash-verified

62 * @see https://en.wikipedia.org/wiki/Kosaraju%27s_algorithm
63 */
64export const kosajaru = (graph: number[][]): number[][] => {
65 const visited = Array(graph.length).fill(false)
66
67 const stack: number[] = []
68 for (let i = 0; i < graph.length; ++i) {
69 getNodePriorities(graph, visited, stack, i)
70 }
71
72 const transposedGraph = transpose(graph)
73
74 const sccs = []
75 visited.fill(false)
76 for (let i = stack.length - 1; i >= 0; --i) {
77 if (!visited[stack[i]]) {
78 const scc: number[] = []
79 gatherScc(transposedGraph, visited, stack[i], scc)
80 sccs.push(scc)
81 }
82 }
83 return sccs
84}

Callers 1

kosajaru.test.tsFile · 0.90

Calls 4

getNodePrioritiesFunction · 0.85
transposeFunction · 0.85
gatherSccFunction · 0.85
pushMethod · 0.65

Tested by

no test coverage detected