-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphHelper.java
More file actions
31 lines (26 loc) · 846 Bytes
/
Copy pathGraphHelper.java
File metadata and controls
31 lines (26 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package ngordnet;
import java.util.Set;
import java.util.TreeSet;
import edu.princeton.cs.algs4.Digraph;
import edu.princeton.cs.algs4.DirectedDFS;
/**
* Provides a method for finding all descendants of a set of vertices in a
* Digraph. See GraphDemo.java for an example of how this class is used.
*
* DO NOT MODIFY THIS FILE.
*
* @author Josh Hug
*/
public class GraphHelper {
/** Returns the set of all vertex numbers reachable from the start vertices. */
public static Set<Integer> descendants(Digraph G, Set<Integer> synsetIDs) {
DirectedDFS dfdp = new DirectedDFS(G, synsetIDs);
TreeSet<Integer> reachable = new TreeSet<Integer>();
for (int i = 0; i < G.V(); i += 1) {
if (dfdp.marked(i)) {
reachable.add(i);
}
}
return reachable;
}
}