Reputation: 1045
Please how can represent a graph in Java ?
I have to apply an algorithm on a graph, the first instruction of the algorithm is to verify if the last vertices are dependent or not ?
after the construction of the graph in java , i shoud verify if the three last point are dependent or not, if they are dependent, the vertice which is the at the head of the arow is replaced by its previous, and verify if the three last point are dependent or not
etc.. until we find three vertice independants
Thank you.
Upvotes: 0
Views: 240
Reputation: 115
To represent a graph in JAVA, you could as well use the ZEST API which has classes like GraphNode, GraphConnection that must be helpful to you.
Upvotes: 0
Reputation: 2533
You could also represent a graph as an adjacency matrix. This is especially good if your graph contains a lot of edges, compared to nodes.
Upvotes: 0
Reputation: 14549
You could stick to a Node
class and either a Vertice
class or a map <Node, Value>
to get that information.
What about
public class Node {
private String description;
private Map<Node, Cost> vertices;
}
That pretty much sums up the basic structure for it. Now it can be iterated to build the paths and workout the information from it
Upvotes: 3