Graph implementation in Java 8
Initialize an undirected graph and add edges.
Graph<String> graph = new Graph<String>(false);
graph.addEdge("A", "B", 2);
graph.addEdge("A", "C", 12);
graph.addEdge("A", "D", 7);
graph.addEdge("C", "B", 1);
graph.addEdge("B", "L", 4);
Print the graph in adjacency list format.
System.out.println(graph);
Breadth First Traversal
graph.breadthFirstTraversal("A")
Depth First Traversal
graph.depthFirstTraversal("A")
Find shortest path using Dijkstra's algorithm
graph.findShortestPath();
Provide code examples and explanations of how to get the project.
Depending on the size of the project, if it is small and simple enough the reference docs can be added to the README. For medium size to larger projects it is important to at least provide a link to where the API reference docs live.
Test cases cover the following
- Depth First Traversal
- Breadth First Traversal
- Dijkstra's algorithm
mvn test
A : [( B, 2 ), ( C, 12 ), ( D, 7 )]
B : [( A, 2 ), ( C, 1 ), ( L, 4 )]
C : [( A, 12 ), ( B, 1 ), ( D, 1 )]
D : [( A, 7 ), ( C, 1 ), ( F, 1 )]
F : [( D, 1 ), ( W, 4 ), ( Z, 4 )]
L : [( B, 4 ), ( W, 1 )]
R : [( Z, 5 )]
W : [( F, 4 ), ( L, 1 )]
Z : [( F, 4 ), ( R, 5 )]
Anyone can contribute to this project.
- What if BFS/DFS start from middle?
- Optimize Dijkstra's algorithm to show intermediate path result
- Load test
- Get graph path from a text file or CSV file
A short snippet describing the license (MIT, Apache, etc.)