I'm implementing some algorithms to teach myself about graphs and how to work with them. What would you recommend is the best way to do that in Java?
I just wanted to ask u if u can give just a short help with a short very simply class definition for directed graph and weighted directed graph?
I looked over the web but i do not want an implementation of it, just a short definition of the classes....what u think is the best data structure to use ? Adjacent Lists?
For an undirected Graph i defined it as follow:
public interface Graph {
Collection vertices(); // returns a collection of all the
// Vertex objects in the graph
Collection edges(); // returns a collection of all the
// Edge objects in the graph
Collection incidentEdges(Vertex v); // returns a collection of
// Edges incident to v
boolean isAdjacent(Vertex v, Vertex w); // return true if v and
} // w are adjacent
public class Vertex {
public boolean visited; // initially false for all vertices
}
public class Edge {
Vertex v1, v2; // undirected edge
Vertex opposite(Vertex v); // given a vertex return the one
} // at the other end of this edge