Let's say we have the graph that is below and we want to print out all the vertices names that there are. How would I be able to reach vertice C if I start exploring at vertice A?
I would assume we use the following implementation for a graph:
class Node {
public int val;
public List<Node> neighbors;
public Node() {
val = 0;
neighbors = new ArrayList<Node>();
}
public Node(int _val) {
val = _val;
neighbors = new ArrayL]ist<Node>();
}
public Node(int _val, ArrayList<Node> _neighbors) {
val = _val;
neighbors = _neighbors;
}
}
If we can't use this implementation, what implementation of a graph can I use so that if I run a depth first search or breadth first search on a directed graph, all of the vertices are discovered?