Skip to content

A* search

networks

Level 3 of 3

Also called A-star and Best-first search with a heuristic.

test yourself

Six questions, four to pick from and two for paper. A to D stand in a row, E to H under them, 10 a step.

fresh numbers: the questions a run answers, asked again on new numbers

choose one

question 1

The search runs from A to D on this map. What estimate does it settle D at?

1510121014101012A30BCDEFG
the answer, and why

the answer is C

The shortest way is A, B, C, D, which is 15 + 14 + 12, so 41. D's line left is 0, so its estimate is 41.

if you chose another

  • That is the straight line from place A to D, not a way along roads.
  • That is A, E, F, G, C, D, longer than 41.
  • That adds only A-B and C-D, leaving out B-C.

question 2

On this map, from E to H, counting E, what way so far does the third place settled have?

101012121010ABE30FGH
the answer, and why

the answer is C

E at 30 and F at 32 come first. Then G at 32, below A's 42 and B's 47. Its way is 12 + 10, so 22.

if you chose another

  • That adds 10 + 10, but road E-F is 12.
  • That is A's way. A's road from E is shorter than F's, but its estimate is 10 + 32, which is 42.
  • That is G's estimate, its way plus its line left of 10.

question 3

Which is true of A* search on a map of nn places with every pair joined?

the answer, and why

the answer is A

Round 1 weighs the start alone. Then at most all the others wait, one fewer each round. Section 4's question 3 adds them up.

this tests where the formula comes from, on the learn page

if you chose another

  • Along one straight row every estimate ties, so it can settle them all, as Dijkstra's method does.
  • The end settled second skips the road, so each road is looked along at most once.
  • That is a line's count. Settling every place here weighs up more, from 3 places on.

question 4

The search runs from the first place after the semicolon to the second. On which map does it weigh up the most places?

the answer, and why

the answer is A

Settling A writes an estimate at all 3 others, and F's 30 is the biggest, so 1, then 3, 2 and 1, which is 7.

if you chose another

  • A line of 4 weighs up one place each round, 4.
  • H is on another part of the map, so the run ends after A and B, 2.
  • B has the smallest estimate and is the place to reach, so the run stops after A, then B and E, 3.

pen and paper

question 5about 8 minutes

The map has roads A-B 35, A-E 10, E-F 10, B-F 10, B-C 10 and F-G 30. The search runs from A to C. The lines left to C are A 20, B 10, E 23, F 15 and G 10.

  1. Write each place settled and its estimate, in order.
  2. Which estimate is written and later beaten?
  3. Which place is never settled, and what is the shortest way?
a hint

Write every estimate down, and cross it out when a smaller one comes.

a worked answer

In the order settled: A 20, E 33, F 35, B 40, C 40. B's 45 becomes 40. G holds 60 and is never settled. The shortest way is A, E, F, B, C, which is 10 + 10 + 10 + 10, so 40.

351010101030ABCEFG
The shortest way, drawn heavy, 40.

this tests how it works, on the learn page

what a full answer includes
  • A 20, E 33, F 35, B 40, C 40.
  • B from 45 to 40.
  • G; A, E, F, B, C, length 40.

question 6about 8 minutes

Four roads, A-E 10, E-F 11, A-B 12 and B-F 3, and the search runs from A to F. The lines left to F are A 15, B 10 and E 10.

  1. What does the search say F is, and what is the shortest?
  2. Where does the line left say too much?
  3. Make B-F 10 instead. What does the search say F is now, and is it right?
a hint

Settle the smallest estimate each round, and stop once F is settled.

a worked answer

Settling A writes E 10 + 10 and B 12 + 10. E, at 20, is settled, and it writes F 21 + 0. F's 21 is below B's 22, so F is settled at 21, and the run stops. The shortest is A, B, F, 12 + 3, so 15. At B the line left says 10 with only 3 left. With B-F at 10, it still says 21, and it is right, as A, B, F is now 22. The lines below are the learn page's question 6, with other numbers.

1011123ABEF
The four roads. B-F is shorter than its straight line, so the watch page's box would refuse it.
Question 6: why must the line left never say too much?
  1. the move: a road shorter than its line

    the line:
    B to F is 2; itsstraight line is 10\begin{gathered} \text{B to F is 2; its} \\ \text{straight line is 10} \end{gathered}
    1121010ABEF
    From A to F. Drawn heavy, the shortest way. The lines left to F are A 15, B 10 and E 10.

    why it is allowed: The watch page's box refuses this road, and this map shows why. At B the line left says 10, when only 2 is left. So it says too much.

  2. the move: the real way looks worse

    the line:
    E is written 20, B 21,then F is written 20\begin{gathered} \text{E is written 20, B 21,} \\ \text{then F is written 20} \end{gathered}

    why it is allowed: Settling A writes E 10 + 10 and B 11 + 10. E is smaller, so it is settled next, and it writes F 20 + 0.

  3. the move: the way through the short road

    the line:
    Z=11+rZ = 11 + r

    why it is allowed: ZZ is the way A, B, F. It is 11 up to B, then rr, the road left. Here rr is 2.

  4. the move: wrong, with no warning

    the line:
    it says 20;the shortest is 13\begin{gathered} \text{it says 20;} \\ \text{the shortest is 13} \end{gathered}

    why it is allowed: F's 20 is below B's 21, so F is settled, and the run stops. By line 3, the way through B is 13. The answer looks like any other, and nothing says it is wrong.

  5. the move: which line failed

    the line:
    an estimate fellfrom 21 to 13\begin{gathered} \text{an estimate fell} \\ \text{from 21 to 13} \end{gathered}

    why it is allowed: Going on from B to F, the estimate falls by 8, against question 4. Question 5's line 6 needs it never to fall.

try it with a small rr: at r=2r = 2, line 3 gives Z=13Z = 13, which you can work out by hand

this tests where the formula comes from, on the learn page

what a full answer includes
  • It says 21; the shortest is 15.
  • At B: it says 10, with only 3 left.
  • It says 21, and it is right: through B is 22.