MCPcopy Index your code
hub / github.com/TheAlgorithms/Go / articulationPointHelper

Function articulationPointHelper

graph/articulationpoints.go:46–89  ·  view source on GitHub ↗

articulationPointHelper recursively traverses the graph using DFS and marks articulation points. It updates `childCount`, `discoveryTime`, and `earliestDiscovery` slices for the given vertex.

(
	apHelperInstance *apHelper,
	vertex int,
	parent int,
	time *int,
	graph *Graph,
)

Source from the content-addressed store, hash-verified

44// articulationPointHelper recursively traverses the graph using DFS and marks articulation points.
45// It updates `childCount`, `discoveryTime`, and `earliestDiscovery` slices for the given vertex.
46func articulationPointHelper(
47 apHelperInstance *apHelper,
48 vertex int,
49 parent int,
50 time *int,
51 graph *Graph,
52) {
53 apHelperInstance.visited[vertex] = true
54
55 // Set discovery and earliest discovery times for the vertex
56 apHelperInstance.discoveryTime[vertex] = *time
57 apHelperInstance.earliestDiscovery[vertex] = *time
58 *time++
59
60 for nextVertex := range graph.edges[vertex] {
61 if nextVertex == parent {
62 continue
63 }
64
65 if apHelperInstance.visited[nextVertex] {
66 // Update the earliest discovery time to the smallest reachable discovery time
67 apHelperInstance.earliestDiscovery[vertex] = min.Int(
68 apHelperInstance.earliestDiscovery[vertex],
69 apHelperInstance.discoveryTime[nextVertex],
70 )
71 continue
72 }
73
74 // Increment child count and perform recursive traversal for DFS
75 apHelperInstance.childCount[vertex]++
76 articulationPointHelper(apHelperInstance, nextVertex, vertex, time, graph)
77
78 // Update the earliest discovery time post DFS
79 apHelperInstance.earliestDiscovery[vertex] = min.Int(
80 apHelperInstance.earliestDiscovery[vertex],
81 apHelperInstance.earliestDiscovery[nextVertex],
82 )
83
84 // Mark vertex as articulation point if condition meets
85 if apHelperInstance.earliestDiscovery[nextVertex] >= apHelperInstance.discoveryTime[vertex] {
86 apHelperInstance.isAP[vertex] = true
87 }
88 }
89}

Callers 1

ArticulationPointFunction · 0.85

Calls 1

IntFunction · 0.92

Tested by

no test coverage detected