Skip to content

Graph data structure implementation in Java programming language

License

Notifications You must be signed in to change notification settings

tgvdinesh/graph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Synopsis

Graph implementation in Java 8

Code Example

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();

Implementation

Installation

Provide code examples and explanations of how to get the project.

API Reference

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.

Tests

Test cases cover the following

  • Depth First Traversal
  • Breadth First Traversal
  • Dijkstra's algorithm
    mvn test

Example # : Graph in Adjacency list

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 )]

Contributors

Anyone can contribute to this project.

TODO

  • 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

License

A short snippet describing the license (MIT, Apache, etc.)

About

Graph data structure implementation in Java programming language

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages