Skip to content

Commit 1fc96de

Browse files
authored
Created ArticulationPoint.java
Created ArticulationPoint.java, expects graph to be generated in accordance with GraphBuilder makeGraph method.
1 parent 3c5ee91 commit 1fc96de

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
class ArticulationPoints{
2+
private static int time;
3+
private static int[] disc, low;
4+
private static boolean[] visited;
5+
6+
public static boolean[] articulationPoints(int[][] graph){
7+
int NumberOfNodes = graph.length;
8+
9+
time = -1;
10+
disc = new int[NumberOfNodes];
11+
low = new int[NumberOfNodes];
12+
visited = new boolean[NumberOfNodes];
13+
java.util.Arrays.fill(low, 2*NumberOfNodes);
14+
15+
boolean[] isAP = new boolean[NumberOfNodes];
16+
for(int i = 0; i< NumberOfNodes; i++)if(!visited[i] && graph[i] != null)apUtil(graph, isAP, i, -1);
17+
return isAP;
18+
}
19+
20+
private static void apUtil(int[][] g, boolean[] isAP, int u, int p){
21+
visited[u] = true;
22+
disc[u] = low[u] = ++time;
23+
24+
int childCount = 0;
25+
for(int v:g[u]){
26+
if(!visited[v]){
27+
apUtil(g, isAP, v, u);
28+
29+
low[u] = Math.min(low[u], low[v]);
30+
childCount++;
31+
32+
if(p != -1 && low[v] >= disc[u])isAP[u] = true;
33+
}else if(v != p)low[u] = Math.min(low[u], disc[v]);
34+
}
35+
if(p == -1 && childCount > 1)isAP[u] = true;
36+
}
37+
}

0 commit comments

Comments
 (0)