File tree Expand file tree Collapse file tree 2 files changed +32
-3
lines changed
src/algorithms/graph/articulation-points Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,35 @@ describe('articulationPoints', () => {
55
55
] ) ;
56
56
} ) ;
57
57
58
+ it ( 'should find articulation points in simple graph with back edge #2' , ( ) => {
59
+ const vertexA = new GraphVertex ( 'A' ) ;
60
+ const vertexB = new GraphVertex ( 'B' ) ;
61
+ const vertexC = new GraphVertex ( 'C' ) ;
62
+ const vertexD = new GraphVertex ( 'D' ) ;
63
+ const vertexE = new GraphVertex ( 'E' ) ;
64
+
65
+ const edgeAB = new GraphEdge ( vertexA , vertexB ) ;
66
+ const edgeBC = new GraphEdge ( vertexB , vertexC ) ;
67
+ const edgeCD = new GraphEdge ( vertexC , vertexD ) ;
68
+ const edgeAE = new GraphEdge ( vertexA , vertexE ) ;
69
+ const edgeCE = new GraphEdge ( vertexC , vertexE ) ;
70
+
71
+ const graph = new Graph ( ) ;
72
+
73
+ graph
74
+ . addEdge ( edgeAB )
75
+ . addEdge ( edgeAE )
76
+ . addEdge ( edgeCE )
77
+ . addEdge ( edgeBC )
78
+ . addEdge ( edgeCD ) ;
79
+
80
+ const articulationPointsSet = articulationPoints ( graph ) ;
81
+
82
+ expect ( articulationPointsSet ) . toEqual ( [
83
+ vertexC ,
84
+ ] ) ;
85
+ } ) ;
86
+
58
87
it ( 'should find articulation points in graph' , ( ) => {
59
88
const vertexA = new GraphVertex ( 'A' ) ;
60
89
const vertexB = new GraphVertex ( 'B' ) ;
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ class VisitMetadata {
14
14
15
15
// We need this in order to check graph root node, whether it has two
16
16
// disconnected children or not.
17
- this . childrenCount = 0 ;
17
+ this . independantChildrenCount = 0 ;
18
18
}
19
19
}
20
20
@@ -57,7 +57,7 @@ export default function articulationPoints(graph) {
57
57
visitedSet [ previousVertex . getKey ( ) ] . childVertex = currentVertex ;
58
58
59
59
// Update children counter for previous vertex.
60
- visitedSet [ previousVertex . getKey ( ) ] . childrenCount += 1 ;
60
+ visitedSet [ previousVertex . getKey ( ) ] . independantChildrenCount += 1 ;
61
61
}
62
62
} ,
63
63
/**
@@ -71,7 +71,7 @@ export default function articulationPoints(graph) {
71
71
// 2. If its visited time is <= low time of adjacent vertex.
72
72
if ( currentVertex === startVertex ) {
73
73
// Check that it has at least two independent children.
74
- if ( visitedSet [ currentVertex . getKey ( ) ] . childrenCount >= 2 ) {
74
+ if ( visitedSet [ currentVertex . getKey ( ) ] . independantChildrenCount >= 2 ) {
75
75
articulationPointsSet . push ( currentVertex ) ;
76
76
}
77
77
} else {
You can’t perform that action at this time.
0 commit comments