Skip to content

Commit 28addb1

Browse files
authored
Create Cut Vertex or Articulation Point
1 parent 6afd494 commit 28addb1

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

Cut Vertex or Articulation Point

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
public class Main {
2+
3+
static int[] low,dfsnum;
4+
static int num=1;
5+
static int noOfVertices;
6+
static boolean[] art;
7+
8+
public static void main(String[] args) {
9+
10+
noOfVertices=7;
11+
12+
int[][] adjMatrix=new int[][]{
13+
{0,1,0,1,0,0,0},
14+
{1,0,1,0,0,0,0},
15+
{0,1,0,1,0,0,1},
16+
{1,0,1,0,1,1,0},
17+
{0,0,0,1,0,1,0},
18+
{0,0,0,1,1,0,0},
19+
{0,0,1,0,0,0,0}
20+
};
21+
low=new int[noOfVertices];
22+
dfsnum=new int[noOfVertices];
23+
art=new boolean[noOfVertices];
24+
25+
cutVertices(adjMatrix,0,-1);
26+
27+
System.out.println("Cut vertex / articulation points are: ");
28+
for(int i=0;i<noOfVertices;i++){
29+
if(art[i]){
30+
System.out.println((char)('A'+i));
31+
}
32+
}
33+
}
34+
35+
static void cutVertices(int[][] adjMatrix, int vertex,int p){
36+
low[vertex]=dfsnum[vertex]=num++;
37+
38+
int child=0;
39+
for(int v=0;v<noOfVertices;v++){
40+
if(adjMatrix[vertex][v]==1) {
41+
if(dfsnum[v]!=0){
42+
low[vertex]=Math.min(low[vertex],dfsnum[v]);
43+
}
44+
else{
45+
child++;
46+
cutVertices(adjMatrix,v,vertex);
47+
low[vertex] = Math.min(low[vertex],low[v]);
48+
if(low[v]>=dfsnum[vertex]){
49+
art[vertex]=true;
50+
}
51+
}
52+
}
53+
}
54+
55+
if(p==-1 && child<2){
56+
art[vertex]=false;
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)