From Definition to Abstraction
- Connect the mathematical definition of Graph to its ADT.
A graph $G = (V, E)$ consists of a nonempty set $V$ of vertices (or nodes) and a collection $E$ of edges (or arcs).
Open the starter code and look at the Graph.java
, which defines the Graph interface:
/**
* Graph ADT.
*
* @param <V> Vertex element type.
* @param <E> Edge element type.
*/
public interface Graph<V, E> {
// Operations not shown
}
The Graph interface declaration looks a lot like the Mathematical definition of Graph, but be careful, as V
and E
here are not collection of vertices/edges. Instead, they are generics, placeholders for the datatype of what will be stored in a vertex or an edge.