levo

Algorithms

The A* algorithm

  • 3 things to know
  • Component 02
Start revising · £5/month

Overview

Recall questions on the A* algorithm and its relation to Dijkstra's, heuristics and g, h and f values, admissible heuristics, a worked A* search, checking admissibility, what the heuristic gains, poor heuristics, and applications of A*.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

Define g, h and f as A* uses them.

Who and when

S joins A with weight 2 and B with weight 2. A joins the goal G with weight 6. B joins C with weight 1, and C joins G with weight 1. The straight-line estimates to G are 3 from S, 5 from A, 2 from B, 1 from C and 0 at G. A* run from S finds the route S, B, C, G. Which node did A* never expand, and what would Dijkstra's algorithm have done?

Key term

For the graph S–A 2, S–B 2, A–G 6, B–C 1, C–G 1 with heuristics 3, 5, 2, 1, 0, verify the heuristic is admissible.

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    What is the A* algorithm and how does it relate to Dijkstra's?

    Model answer

    A* is a shortest-path algorithm that works exactly like Dijkstra's, except that when it chooses the next node to expand it does not use the distance travelled alone. It adds an estimate of the distance still to go, so the search is steered towards the destination instead of spreading equally in all directions.

  2. 2

    What is a heuristic in this context?

    Model answer

    An estimate, calculated by a rule of thumb, of the cost of getting from a given node to the destination. It is not measured by exploring the graph; it is computed cheaply from what is known about the node, such as its position, so that it costs almost nothing to obtain.

  3. 3

    Define g, h and f as A* uses them.

    Model answer

    For a node, g is the actual cost of the best route found so far from the start to that node. h is the heuristic estimate of the cost from that node onwards to the destination. f is the sum of the two, an estimate of the total cost of a route through that node, and A* always expands the unvisited node with the smallest f.

  4. 4

    What does it mean for a heuristic to be admissible, and why does it matter?

    Model answer

    An admissible heuristic never overestimates the true remaining cost to the destination; it may be exactly right or too low, but never too high. It matters because it is the condition that guarantees A* returns a genuinely shortest path. If a heuristic overestimates, A* can dismiss the route that was actually cheapest and return a worse one.

  5. 5

    Give an example of an admissible heuristic for route finding, and explain why it is admissible.

    Model answer

    The straight-line distance from a junction to the destination. It is admissible because no road route can be shorter than the straight line between two points, so the estimate can never exceed the true road distance. On a grid where movement is restricted to horizontal and vertical steps, the number of squares across plus the number of squares up serves the same purpose.

  6. 6

    What happens to A* if the heuristic is zero for every node?

    Model answer

    It becomes Dijkstra's algorithm exactly. With h always zero, f equals g, so the node chosen next is simply the one with the smallest distance from the start, which is Dijkstra's selection rule. Dijkstra's is therefore the special case of A* with no guidance about where the destination is.

Other ways to work this

The same content, four other ways.

Everything in your subscription

Runs, plus a mode for every other kind of session.

1Flash
2Imposter
3Fade
4Brain dump

Learn every subtopic in runs of four questions

Facts flash and fade, a wrong word hides in some of them, and a brain dump decides which questions are locked in.

Processors: Structure, Performance and Types
Input, Output and Storage
Systems Software
Applications Generation

Cram the night before, weakest topic first

A quick scan finds your weakest topics. Recall each fact you missed three times in a row.

If it matches, the search .
succeedsfailsrestarts

Blank Blitz consolidates the facts

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

✓What it iscovered
~Why it happenspartly there
How long it lastsnot there yet

Explain It tests your understanding

Explain a concept in your own words and see which of its points you covered.

A global variable means a variable reachable from anywhere in the program.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The faults are the mistakes students make most often.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Every question in Algorithms, on a schedule.

Learn it in runs of four questions, each ending on a brain dump against the clock. Every question you lock in comes back the next day, then at longer gaps, each time just before you would forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.