Skip to content

pmanthan009/graph-visualizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Graph Algorithm Visualizer (JavaFX)

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.


Features

✅ Algorithms

  • BFS (Breadth-First Search) — press B
  • DFS (Depth-First Search) — press D
  • Dijkstra (Shortest Path on weighted graph) — click START + TARGET, then press J

✅ Visualization

  • 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

✅ Interaction

  • Click nodes to select Dijkstra endpoints:
    • START = purple
    • TARGET = red
  • Dijkstra runs until TARGET is finalized, then reconstructs and highlights the shortest path

Controls

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 B or D clears the START/TARGET selection and any highlighted shortest path.


Project Structure

GraphVisualizer/ └── src/ └── app/ ├── MainApp.java ├── GraphNode.java ├── Edge.java ├── BFSAlgorithm.java ├── DFSAlgorithm.java └── DijkstraAlgorithm.java


Requirements

  • Java 17+ recommended (Java 21+ works great)
  • JavaFX SDK (e.g. JavaFX 23)
  • Windows/macOS/Linux supported

How to Run (PowerShell / Windows)

From the src directory:

Compile

javac --module-path "C:\javafx\javafx-sdk-23.0.2\lib" --add-modules=javafx.controls,javafx.fxml app/*.java

Run

java --module-path "C:\javafx\javafx-sdk-23.0.2\lib" --add-modules=javafx.controls,javafx.fxml app.MainApp

If 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.).

Future Improvements

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

About

Visual tool built in JavaFX to demonstrate graph traversal and shortest-path algorithms with interactive node selection and live simulation.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages