Consist of:
This is a special kind of graph where
These graphs can be sorted topologically
Adjacency list:
public class Graph { private int n; private final List<List<Integer>> adj; public Graph(int n) { this.n = n; this.adj = createAdjacentList(n); } private static List<List<Integer>> createAdjacentList(int n) { List<List<Integer>> res = new ArrayList<List<Integer>>(n); int i = 0; while (i < n) { res.add(new LinkedList<Integer>()); i++; } return res; } public void addEdge(int v, int u) { adj.get(v).add(u); } public Iterable<Integer> adjacent(int v) { return adj.get(v); } public int getN() { return n; } }