An interactive JavaFX application that visualizes common graph algorithms step-by-step.
Supports BFS, DFS, and Dijkstra’s shortest path with real-time simulation, node state coloring, traversal order labels, and shortest-path highlighting.
- BFS (Breadth-First Search) — press
B - DFS (Depth-First Search) — press
D - Dijkstra (Shortest Path on weighted graph) — click START + TARGET, then press
J
- Node states:
- Blue = unvisited
- Yellow = discovered / in queue (frontier)
- Green = visited / processed
- Traversal order numbers displayed on visited nodes
- Dijkstra displays:
- tentative distances during execution
- final shortest path highlighted
- total path cost shown in the window
- On-screen HUD/guide explaining key controls
- Click nodes to select Dijkstra endpoints:
- START = purple
- TARGET = red
- Dijkstra runs until TARGET is finalized, then reconstructs and highlights the shortest path
| Action | Input |
|---|---|
| Run BFS | B |
| Run DFS | D |
| Select START node (Dijkstra) | click a node |
| Select TARGET node (Dijkstra) | click a different node |
| Run Dijkstra | J |
Tip: After running Dijkstra, pressing
BorDclears the START/TARGET selection and any highlighted shortest path.
GraphVisualizer/ └── src/ └── app/ ├── MainApp.java ├── GraphNode.java ├── Edge.java ├── BFSAlgorithm.java ├── DFSAlgorithm.java └── DijkstraAlgorithm.java
- Java 17+ recommended (Java 21+ works great)
- JavaFX SDK (e.g. JavaFX 23)
- Windows/macOS/Linux supported
From the src directory:
javac --module-path "C:\javafx\javafx-sdk-23.0.2\lib" --add-modules=javafx.controls,javafx.fxml app/*.javajava --module-path "C:\javafx\javafx-sdk-23.0.2\lib" --add-modules=javafx.controls,javafx.fxml app.MainAppIf your JavaFX path is different, update the --module-path value.
Notes
BFS/DFS use an unweighted adjacency list.
Dijkstra uses a weighted adjacency list with a priority queue, and stores predecessors (prev) to reconstruct the final shortest path.
The code separates algorithm logic from UI for clean design and easy extension (e.g., add A*, Bellman-Ford, etc.).
UI buttons (Play/Pause/Step)
Click-to-start BFS/DFS as well
A* search visualization
Random graph generator / import graph from file
Display queue/stack/priority queue contents in the HUD