A* Star Pathfinding Algorithm
Performance
Time Complexity:
Varies
Space Complexity:
Varies
Search Countours:
Stretched
What are Search contours?
Pathfinding Stats
Status
Running...
Visited Node Count:
0
Path Length:
0
Grid size: 20 x 20, Walls: 0
⚠️ Note: this animated visualization is a work-in-progress. If you are encountering errors or want to replay the animation, please refresh the page.
If you would like to report a bug or suggest an improvement, please create an issue on GitHub.
Understanding A* Star
A* operates on a graph or a grid where each node represents a point in space, and edges represent possible transitions between nodes. The algorithm requires information about the cost of moving from one node to another and a heuristic function that estimates the cost from a given node to the goal.
A priority queue (often implemented using a min-heap) is used to keep track of the nodes to be explored. Nodes are prioritized based on their total cost.
To implement this sorting algorithm, we initialize the start node and add it to the priority queue with a priority value of the heuristic estimate from the start to the goal. Set the cost to reach the start node as 0. While the priority queue is not empty, we remove the node with the lowest priority value from the queue and mark it as visited. If the node is the goal, we have found the shortest path. Otherwise, we add all of the node's neighbors to the priority queue with a priority value of the cost to reach the current node plus the heuristic estimate from the neighbor to the goal. If the neighbor is already in the priority queue, we update its priority value if the new value is lower than the old one. Finally, the algorithm terminates when the priority queue is empty or the goal node is removed from the queue.
Code Implementation
A* Star can be implemented in a variety of languages. Below are some examples of implementations in Python, C++, Go, and Java.
Note: these implementations are for educational purposes only, such as preparing for a technical interview or for learning about sorting algorithms. They are not intended to be used in production as-is, as they may not be optimized.