4
4
5
5
/**
6
6
* Created by Mayur Kulkarni on 2/5/2017.
7
+ *
7
8
*/
8
9
public class Graph <T > implements Iterable <T > {
9
10
/**
@@ -79,8 +80,8 @@ public int edgeWeight(T fromNode, T toNode) {
79
80
/**
80
81
* Inserts toNode to the adjacency list of fromNode
81
82
*
82
- * @param fromNode from node
83
- * @param toNode to node
83
+ * @param fromNode from node
84
+ * @param toNode to node
84
85
*/
85
86
private void insertIntoGraphMap (T fromNode , T toNode ) {
86
87
graph .compute (fromNode , (key , value ) -> {
@@ -137,7 +138,7 @@ public void addEdge(T fromNode, T toNode, int weight) {
137
138
/**
138
139
* Returns the adjacency list of the graph
139
140
* @param key the index of node you're interested in
140
- * @return adjacency list of node specifief in key
141
+ * @return adjacency list of node specific in key
141
142
*/
142
143
public List <T > adjacencyList (T key ) {
143
144
@@ -170,11 +171,11 @@ public Set<T> articulationPoints() {
170
171
* 2. if current node is root node of DFS, and has more than 2 independent children
171
172
* for more: https://adventinprogramming.wordpress.com/2017/02/05/articulation-points-in-graph/
172
173
*
173
- * @param visited denotes the nodes which are already visited
174
- * @param visitedTime denotes the order in which nodes are visited
175
- * @param currNode the current node of this traversa ;
176
- * @param lowTime denotes the minimum lowTime of adjacent vertices
177
- * @param parent parent of the current node
174
+ * @param visited denotes the nodes which are already visited
175
+ * @param visitedTime denotes the order in which nodes are visited
176
+ * @param currNode the current node of this traversal ;
177
+ * @param lowTime denotes the minimum lowTime of adjacent vertices
178
+ * @param parent parent of the current node
178
179
* @param articulationPoints articulation points of the current graph
179
180
*/
180
181
public void DFSArticulationPoint (Set <T > visited ,
@@ -198,10 +199,12 @@ public void DFSArticulationPoint(Set<T> visited,
198
199
if (visitedTime .get (currNode ) <= lowTime .get (adjNode )) {
199
200
isArticulationPoint = true ;
200
201
} else {
201
- lowTime .compute (currNode , (node , nodeLowTime ) -> Math .min (lowTime .get (currNode ), lowTime .get (adjNode )));
202
+ lowTime .compute (currNode , (node , nodeLowTime ) ->
203
+ Math .min (lowTime .get (currNode ), lowTime .get (adjNode )));
202
204
}
203
205
} else {
204
- lowTime .compute (currNode , (node , lowtime ) -> Math .min (lowTime .get (currNode ), lowTime .get (adjNode )));
206
+ lowTime .compute (currNode , (node , lowtime ) ->
207
+ Math .min (lowTime .get (currNode ), lowTime .get (adjNode )));
205
208
}
206
209
}
207
210
// first condition is satisfied only by root nodes of tarjanSCC, for rest of them there's
@@ -216,9 +219,9 @@ public void DFSArticulationPoint(Set<T> visited,
216
219
* Tell whether the currNode is the root of the tarjanSCC or not.
217
220
* The root of the tarjanSCC will have null as it's parent
218
221
*
219
- * @param currNode The node you're interested in
220
- * @param parent parent HashMap who's key is node and value is it's parent
221
- * @return
222
+ * @param currNode The node you're interested in
223
+ * @param parent parent HashMap who's key is node and value is it's parent
224
+ * @return or not it is root
222
225
*/
223
226
private boolean isRoot (T currNode , Map <T , T > parent ) {
224
227
return parent .get (currNode ) == null ;
0 commit comments