Skip to content

Commit

Permalink
Created ArticulationPoint.java
Browse files Browse the repository at this point in the history
Created ArticulationPoint.java, expects graph to be generated in accordance with GraphBuilder makeGraph method.
  • Loading branch information
taran-1407 authored Oct 2, 2020
1 parent 3c5ee91 commit 1fc96de
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions ArticulationPoint/ArticulationPoint.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class ArticulationPoints{
private static int time;
private static int[] disc, low;
private static boolean[] visited;

public static boolean[] articulationPoints(int[][] graph){
int NumberOfNodes = graph.length;

time = -1;
disc = new int[NumberOfNodes];
low = new int[NumberOfNodes];
visited = new boolean[NumberOfNodes];
java.util.Arrays.fill(low, 2*NumberOfNodes);

boolean[] isAP = new boolean[NumberOfNodes];
for(int i = 0; i< NumberOfNodes; i++)if(!visited[i] && graph[i] != null)apUtil(graph, isAP, i, -1);
return isAP;
}

private static void apUtil(int[][] g, boolean[] isAP, int u, int p){
visited[u] = true;
disc[u] = low[u] = ++time;

int childCount = 0;
for(int v:g[u]){
if(!visited[v]){
apUtil(g, isAP, v, u);

low[u] = Math.min(low[u], low[v]);
childCount++;

if(p != -1 && low[v] >= disc[u])isAP[u] = true;
}else if(v != p)low[u] = Math.min(low[u], disc[v]);
}
if(p == -1 && childCount > 1)isAP[u] = true;
}
}

0 comments on commit 1fc96de

Please sign in to comment.