This Java project implements Breadth-First Search (BFS) and Dijkstra's Algorithm for an edge-weighted graph using custom Vertex objects (instead of raw edges).
The assignment required creating a graph representation where each vertex holds a map of its adjacent vertices along with the weight of the edge between them. Two search algorithms were implemented:
- Breadth-First Search (BFS) — for unweighted path discovery.
- Dijkstra’s Algorithm — for shortest path discovery in a weighted graph.
All algorithms work based on the following class structure:
Vertex<V>WeightedGraph<V>Search<V>(interface)BreadthFirstSearch<V>DijkstraSearch<V>Main— for testing and usage example.
- Java 8+
- No external libraries used (standard library only)
src/
│
├── Vertex.java
├── WeightedGraph.java
├── Search.java
├── BreadthFirstSearch.java
├── DijkstraSearch.java
└── Main.java
Running Main.java:
BFS Path to Z: [A, C, D, Z]
Dijkstra Path to Z: [A, C, B, D, E, Z]
-
Clone the repository
-
Compile all
.javafiles:javac *.java -
Run the
Mainclass:java Main