Visualizer for A* search algorithm in C using
raylib.
A* is a pathfinding algorithm that finds the shortest path between source and destination using a goal-directed heuristic.
demo.mp4
- Clone the repository
git clone https://github.com/nishantHolla/a-star-visualizer
cd a-star-visualizer
- Run make
make release
- Execute the program
./out/asv
A* is an informed search algorithm that finds the shortest path between a source vertex and a destination
vertex in a weighted graph. It does this by maintaining a tree of paths originating at the start node
and extending those paths one edge at a time until the goal node is reached.
At each iteration of the search, A* holds a cost map of all visited nodes that is calculated by the
formula
where
-
$g(n)$ is the cost of the path from the start node to node n -
$h(n)$ is the heuristic function that approximates how close node n is to the destination node -
$f(n)$ is the total cost of node n that is used to determine if a node is worthwhile to visit.
This implementation of A* uses a priority queue to store the neighbors of the current cell with the
priority of their cost. Since cost must be minimized, the cells with low cost are prioritized over cells
with higher cost.
The heuristic function
For a graph where diagonal traversal is allowed, Euclidean distance is used as a heuristic which is given by
where
The time complexity of A* is given by