A Java project for visualizing the Breadth-First Search (BFS) algorithm step by step.
The application reads a graph definition from a .txt file, runs BFS, and displays the search process visually using JavaFX.
- step-by-step BFS visualization
- highlights node expansion and traversal order
- multiple example input files
- reconstructs and displays the final path
- accepts comments and flexible spacing in input files
A short video demonstration of the project:
https://youtu.be/VT-ZhxdzErE
This visualizer demonstrates Breadth-First Search, which explores nodes level by level.
Important note:
- BFS finds the path with the fewest steps / edges
- during BFS, each expansion step is treated uniformly; BFS ignores edge weights while choosing which node to expand next
- the displayed total path cost is determined afterwards from the costs defined in the input file
Run the project with:
mvn clean javafx:run -Djavafx.args="--ssf src/main/resources/intro.txt"Other example files:
mvn clean javafx:run -Djavafx.args="--ssf src/main/resources/simple_ex.txt"
mvn clean javafx:run -Djavafx.args="--ssf src/main/resources/1_to_9.txt"
mvn clean javafx:run -Djavafx.args="--ssf src/main/resources/greek_alphabet.txt"
mvn clean javafx:run -Djavafx.args="--ssf src/main/resources/california.txt"
mvn clean javafx:run -Djavafx.args="--ssf src/main/resources/21_nodes.txt"
mvn clean javafx:run -Djavafx.args="--ssf src/main/resources/100_nodes.txt"The graph is provided through a .txt file.
- First line — start state
- Second line — one or more goal states
- Remaining lines — transitions for each state
state: next_state1,cost1 next_state2,cost2
Example:
A
G
A: B,1 C,2
B: D,3 E,1
C: F,2 G,4
- extra spaces are tolerated
- comments can be added with
# - each transition line must start with a state name followed by
: - each successor must include both a state name and a cost
The project includes several example inputs in src/main/resources:
intro.txtsimple_ex.txt1_to_9.txtgreek_alphabet.txtcalifornia.txt21_nodes.txt100_nodes.txt
Represents one node in the search.
Stores:
state— node namecost— cost from the parent nodedepth— level in the search treeparent— node from which this node was reached
Contains the main BFS logic.
Uses:
stateSpace— graph built from the input fileopen— queue of discovered nodes waiting to be processedtree— expanded nodespath— final reconstructed path from the start state to the goal statevisitedStates— prevents revisiting nodesbfsEvents— events used for visualization
Represents one event in the BFS animation.
Defines all possible event types used by the visualizer.
Contains the graphical animation logic and displays the BFS process step by step.
- In
open, nodes are ordered by value and then alphabetically. - BFS itself expands nodes by level.
- The final displayed path cost is calculated from the edge costs defined in the input file.