8.1.12

A* Algorithm

Test yourself

A* algorithm

An improved version of Dijkstra’s algorithm. A finds the shortest path from a starting point to a goal on a graph. A combines actual travel costs and estimated costs to prioritize promising paths.

Illustrative background for Step-by-Step OverviewIllustrative background for Step-by-Step Overview ?? "content

Step-by-Step Overview

  • Steps include:
    • 1 Initialization
    • 2 Cost Calculation
    • 3 Explore
    • 4 Expand Neighbors
    • 5 Close Node
    • 6 Repeat
    • 7 Reconstruct Path
Illustrative background for InitializationIllustrative background for Initialization ?? "content

Initialization

  • Step 1 Initialization
    • Start with an open list (to explore) and a closed list (evaluated).
    • Add the starting point to the open list with an initial cost of 0.
Illustrative background for Cost calculationIllustrative background for Cost calculation ?? "content

Cost calculation

  • Step 2: Cost Calculation
  • For each node, calculate:
    • g(n): Cost from the start to the node.
    • h(n): Estimated cost from the node to the goal.
    • Total cost: f(n) = g(n) + h(n).
Illustrative background for ExploreIllustrative background for Explore ?? "content

Explore

  • Step 3: Explore
    • While the open list isn’t empty:
    • Select the node with the lowest f(n) (current node).
    • If it’s the goal, reconstruct the path and finish.
Illustrative background for Expand neighborsIllustrative background for Expand neighbors ?? "content

Expand neighbors

  • Step 4: Expand Neighbors
    • For each neighbor of the current node:
    • Calculate new g(n). If it’s lower than before, update costs and set the current node as the neighbor’s parent.
    • Add the neighbor to the open list if not already present.
Illustrative background for Close node, repeat, reconstruct pathIllustrative background for Close node, repeat, reconstruct path ?? "content

Close node, repeat, reconstruct path

  • Step 5: Close Node
    • Move the current node to the closed list.
  • Step 6: Repeat
    • Go back to step 3 until the goal is found or no paths remain.
  • Step 7: Reconstruct Path
    • If the goal is reached, trace back from the goal to the start using parent pointers to get the path.

Jump to other topics

1Components of a Computer

2Software & Software Development

3Exchanging Data

4Data Types, Data Structures & Algorithms

5Legal, Moral, Cultural & Ethical Issues

6Elements of Computational Thinking

6.1Thinking Abstractly

6.2Thinking Ahead

6.3Thinking Procedurally

6.4Thinking Logically

6.5Thinking Concurrently

7Problem Solving & Programming

8Algorithms

Unlock your full potential with Seneca Premium

  • Unlimited access to 10,000+ open-ended exam questions

  • Mini-mock exams based on your study history

  • Unlock 800+ premium courses & e-books

Get started with Seneca Premium