AStar - explanation of name
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
The A* algorithm, often pronounced "A-Star", is a cornerstone in the realm of pathfinding and graph traversal algorithms. It is renowned for its performance and accuracy, facilitating applications ranging from artificial intelligence in games to robotics and network routing. To fully grasp the significance of A*, it's essential to delve into its etymology, technical aspects, and practical applications.
Origin of the Name
The "A" in A* stands for an algorithm type (`algorithm A`), which specifically signifies that it is a general search algorithm. The asterisk (``) denotes its optimal, heuristic nature. This combination indicates that A is an optimal, refined successor to the basic algorithm, designed to find the least cost path in a graph.
Technical Explanation
A* merges aspects of Dijkstra’s algorithm and Greedy Best-First Search. It computes the shortest path by considering both the cost of the path from the start node (`g(n)`) and the estimated cost to the goal (`h(n)`), also known as the heuristic. The sum of these two components is what influences the choice of path, captured by the function:
Where:
- = Cost from the start node to node .
- = Estimated cost from node to the goal.
The choice of heuristic function is critical to the efficiency of A*. The function must be admissible, meaning it never overestimates the actual cost to reach the goal, ensuring the algorithm’s optimality.
Example
Consider a grid-like graph where a robot explores a maze. Here, could represent the number of steps from the start to the current point, while might utilize the Manhattan distance to estimate the remaining steps to the goal.
Steps in A* Algorithm
- Initialize the open list with the start node.
- Keep a closed list of nodes already evaluated.
- Loop, processing each node:
- Select the node with the lowest from the open list.
- If it is the goal, reconstruct and return the path.
- Otherwise, generate its neighbors.
- For each neighbor:
- If it is not in the open list or offers a lower , update its .
- Add it to the open list.
- Repeat until the goal is reached or the open list is empty.
The Heuristic Function’s Role
- Admissible: Never overestimates the cost to reach the goal. Ensures paths found are optimal.
- Consistent (Monotonic): For every node and successor , the estimated cost should satisfy: Where is the step cost to the neighbor. A* uses this property to enhance efficiency by not revisiting nodes, enabling the open list order.
Applications of A*
- Game Development: A* is widely used in games for AI pathfinding, determining optimal movements or decisions for character navigation in complex environments.
- Robotics: Robots utilize A* for mapping out routes in unstructured environments, balancing between speed and path optimality.
- Network Routing: Finds the shortest path for data packets between nodes in a network.
- Geographic Information Systems (GIS): Helps in terrain navigation by assimilating elevation data into path cost calculations.
Example Implementation
Here is a pseudo-code outline for A*:
Related reading
- Asynchronous computation in TensorFlow
- At what stage is a tensorflow graph set up?
- Attach a queue to a numpy array in tensorflow for data fetch instead of files?
- Attach a queue to a numpy array in tensorflow for data fetch instead of files?
- Asymptotically optimal algorithm to compute if a line intersects a convex polygon
- At which n does binary search become faster than linear search on a modern CPU?
- Attempting to perform BLAS operation using StreamExecutor without BLAS support error occurs
- Attempting to reset tensorflow graph when using keras, failing

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.