MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / transpose

Method transpose

graph/kosaraju.go:64–80  ·  view source on GitHub ↗

Helper function to create a transposed (reversed) graph.

()

Source from the content-addressed store, hash-verified

62
63// Helper function to create a transposed (reversed) graph.
64func (g *Graph) transpose() *Graph {
65 transposed := &Graph{
66 vertices: g.vertices,
67 edges: make(map[int]map[int]int),
68 }
69
70 for v, neighbors := range g.edges {
71 for neighbor := range neighbors {
72 if transposed.edges[neighbor] == nil {
73 transposed.edges[neighbor] = make(map[int]int)
74 }
75 transposed.edges[neighbor][v] = 1 // Add the reversed edge
76 }
77 }
78
79 return transposed
80}
81
82// Helper DFS function used in the transposed graph to collect SCCs.
83func (g *Graph) dfs(v int, visited []bool, scc *[]int) {

Callers 1

KosarajuMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected