CS With NehalCS With Nehal

A* Algorithm

Show pathfinding using cost, heuristic, and total estimated distance.

Start:A▼
Target:E▼
Graph Type: Undirected
Nodes (V): 5
Target (End): E
A* Pathfinding Basic
A standard graph where the heuristic (h) guides the algorithm towards the target more efficiently than Dijkstra.
Priority Queue (Min f-score)
Empty
42158102
A
g:0h:0f:0
Start
B
g:∞h:0f:∞
C
g:∞h:0f:∞
D
g:∞h:0f:∞
E
g:∞h:0f:∞
End
Animation Speed — 1000ms

A* Evaluation Table

Formula: f(n) = g(n) + h(n)
Node Cost g(n)Heuristic h(n)Total f(n)PreviousVisited
AStart000-0
B∞0∞-0
C∞0∞-0
D∞0∞-0
E∞0∞-0
Final Path:
Pending calculation...

About This Simulation

This A* search simulator shows how the algorithm finds a shortest path by combining the cost so far, g(n), with a heuristic estimate of the remaining distance, h(n). You can see the open and closed lists and the f, g and h values of every node.

Features

  • Build a graph with edge costs and heuristic values
  • Open list (frontier) and closed list shown at every step
  • g(n), h(n) and f(n) = g(n) + h(n) for each node
  • Node expansion order and the final path highlighted
  • Step-by-step playback and fullscreen mode

Explanation

A* is an informed search algorithm that always expands the node with the smallest f(n) = g(n) + h(n), where g(n) is the cost from the start to n and h(n) is an estimate of the cost from n to the goal. With a good heuristic it reaches the goal while exploring far fewer nodes than Dijkstra.

How it works

  1. Put the start node in the open list with g = 0 and f = h(start).
  2. Remove the node with the smallest f value from the open list. If it is the goal, stop and trace the path back through the parent links.
  3. Move the node to the closed list.
  4. For each neighbour, compute g = g(current) + edge cost. If this is better than any g found before, update its parent, g and f = g + h, and add it to the open list.
  5. Repeat until the goal is reached or the open list is empty (no path).

Why it matters

A* is the standard pathfinding algorithm in games, robotics and map navigation. It appears in artificial intelligence courses (CSE440, CSE420, CSE427) and connects graph algorithms from CSE221 with heuristic search.

Frequently Asked Questions

What is f(n) = g(n) + h(n) in A*?

g(n) is the actual cost of the path from the start to node n, h(n) is the heuristic estimate of the cost from n to the goal, and f(n) is the estimated total cost of the cheapest path through n.

What is an admissible heuristic?

A heuristic is admissible if it never overestimates the true cost to reach the goal: h(n) ≤ actual cost from n to the goal for every node. With an admissible heuristic, A* tree search is guaranteed to find an optimal path.

What is a consistent (monotone) heuristic?

A heuristic is consistent if h(n) ≤ cost(n, m) + h(m) for every edge from n to m. Consistency implies admissibility and guarantees that A* graph search never needs to reopen a closed node.

How is A* different from Dijkstra's algorithm?

Dijkstra expands nodes by g(n) only, so it searches in every direction. A* adds the heuristic h(n) to steer the search toward the goal. Dijkstra is the same as A* with h(n) = 0.

Topics covered

  • A* Search
  • Informed (Heuristic) Search
  • Admissible Heuristics
  • Consistent Heuristics
  • Shortest Path
  • Pathfinding

Tags

  • a star
  • a*
  • heuristic
  • informed search

Related Simulations

Acknowledgements

The Person Behind This Simulation

This simulation would not have been possible without his valuable contributions and support. We sincerely appreciate his time, effort, and dedication to the project.

Tahsin Uddin Labib

Tahsin Uddin Labib

  • 4th Year CS Undergraduate Student | BRAC University