Working Backwards from the Goal

Ask what would produce the answer you want.

Start at the goal

You have two jugs with no markings, one holding 3 units and one holding 5, a tap, and a drain. You can fill a jug to the top, empty it, or pour one jug into the other until the first is empty or the second is full. The goal is exactly 4 units in the large jug.

Pouring at random can go on for a long time, because every state offers several moves. Working backwards turns the question round: instead of asking where a move leads, ask which state would give the answer in one more move.

What would produce it

Four is 5 − 1. So one way to finish is a full large jug that loses exactly 1 unit. Pouring the large jug into the small one moves as much as the small jug has room for, and the small jug has room for exactly 1 when it already holds 2, because 3 − 2 = 1.

So the state before the goal is 5 in the large jug and 2 in the small one. Write a state as (large, small): the goal is (4, 3), and the state before it is (5, 2).

That turns the problem into a smaller one: how do you get 2 into the small jug? Work backwards again. With the large jug empty, 2 in the small jug comes from pouring 2 across from the large jug; and 2 in the large jug, with the small jug empty, comes from filling the small jug from a full large one, which leaves 5 − 3 = 2, and then emptying the small jug.

5,21,32,23,14,34,0

Each state is (large, small). The four states on the left reach 4 in the large jug with one pour. The dashed two, (2, 2) and (3, 1), can never occur. The gold step is the one the lesson takes, from (5, 2).

Read it forward

The chain now reaches back to the empty jugs, so read it forward as the solution. Fill the large jug: (5, 0). Pour it into the small jug until that is full: (2, 3). Empty the small jug: (2, 0). Pour the 2 across: (0, 2).

Fill the large jug again: (5, 2). Pour it into the small jug, which takes only 1 unit: (4, 3). The large jug holds exactly 4.

The solution was found from the end, and it is written from the start. Every move in it is one of the three allowed moves, and each state follows from the one before it.

largesmallstart00fill 550pour23empty 320pour02fill 552pour43

The amounts in the 5-unit and 3-unit jugs after each move. Six moves leave 4 in the large jug, and a search through every possible move finds no shorter way.

Why the search narrows

Searching forward, every state offers up to six moves (fill, empty or pour, with either jug), and most of them lead nowhere useful. Searching backward, only a few states could produce the goal at all.

Leaving aside states that already hold 4 in the large jug, exactly four states give 4 there after one pour: (5, 2), pouring into the small jug, and (1, 3), (2, 2) and (3, 1), pouring into the large one. Two of those can be crossed off at once. Every move leaves one jug empty or full: filling makes one full, emptying makes one empty, and a pour stops when the first jug is empty or the second is full. So (2, 2) and (3, 1) never occur.

The other survivor, (1, 3), also works, but it takes longer: fill the small jug, pour it into the large one, fill it again, pour until the large jug is full, leaving 1, empty the large jug, pour the 1 across, fill the small jug, and pour it in. That is 8 moves, against 6 for the route through (5, 2).

Undoing a chain of operations

A number is doubled, and then 7 is added, giving 23. Working forward means guessing the number. Working backward undoes the operations, the last one first: before 7 was added the number was 23 − 7 = 16, and before it was doubled it was 16 ÷ 2 = 8.

The order matters. Undoing in the original order, halving first and then taking 7 away, gives 23 ÷ 2 − 7 = 4.5, and 4.5 doubled plus 7 is 16, not 23. The last thing done is the first to undo, as the last layer put on is the first taken off.

8× 216+ 723

Forward: 8 doubled is 16, and 16 + 7 = 23.

23− 716÷ 28

Backward: the same two steps undone in reverse order, each by its opposite, lead from 23 back to 8.

Finding a proof

Working backward is how many proofs are found. Suppose you want to prove that a² + b² ≥ 2ab for all numbers a and b. Ask what would give it: it would follow from a² − 2ab + b² ≥ 0. And that left side is (a − b)², which is a square, and a square is never negative. The chain has reached something already known.

Now write the proof forward, from the known fact to the goal: (a − b)² ≥ 0, so a² − 2ab + b² ≥ 0, so a² + b² ≥ 2ab. Each line follows from the one before it.

Each backward step has to run forward as well. Here it does, because adding 2ab to both sides can be undone by taking it away. A step such as squaring both sides cannot always be undone: −3 and 3 have the same square. A chain found backward is a proof only once every link is checked in the forward direction.

The usual mistakes

Undoing in the wrong order. In the doubling puzzle, halving 23 before taking away 7 gives 4.5, not 8.

Writing up the backward chain as the proof. A proof that starts from a² + b² ≥ 2ab assumes what it sets out to prove. The steps are found from the goal and written from the hypothesis.

Stopping at a state that cannot be reached. (2, 2) would leave 4 in the large jug with one pour, but no sequence of moves ever produces it, so a chain that leads back to it is a dead end.

A culture and a dinner

In the first application below, a culture doubles each hour and then loses a harvest, so an hour is undone by adding the harvest back and then halving. In the second, a dinner time is fixed and every task is timed back from it.

Worked example: A Bacterial Culture That Doubles Every Hour and Is Harvested at the End of Each Hour

Question A laboratory grows bacteria in a bioreactor. During each hour the number of cells doubles, and at the end of the hour a technician harvests 3200 million cells for testing. (a) At the end of the fourth hour, just after the harvest, the culture holds 8000 million cells. How many cells did it hold at the start? (b) For a new batch the technician needs six harvests, one at the end of each of the first six hours, and every harvest must take the full 3200 million cells. What is the smallest number of cells the new batch can start with?

  1. 1.Going forward, an hour takes a count of x million cells to 2x − 3200. To run an hour backwards, undo the last move first: add back the 3200 harvested, then halve. So a count of y at the end of an hour came from y + 32002 at its start.

    Million cells at the end of each hour, after the harveststarthour 1hour 2hour 3hour 48000One hour back: add the 3200 harvested, then halve
    Million cells at the end of each hour, after theharveststarthour 1hour 2hour 3hour 48000One hour back: add the 3200 harvested, thenhalve
    An hour doubles the cells and then removes 3200 million, so running an hour back adds 3200 million and then halves.
  2. 2.Start from the end of the fourth hour. 8000 + 32002 = 5600 at the end of the third hour, 5600 + 32002 = 4400 at the end of the second, and 4400 + 32002 = 3800 at the end of the first.

    Million cells at the end of each hour, after the harveststarthour 1hour 2hour 3hour 43800440056008000One hour back: add the 3200 harvested, then halve8000 + 3200 = 11200, half is 5600
    Million cells at the end of each hour, after theharveststarthour 1hour 2hour 3hour 43800440056008000One hour back: add the 3200 harvested, thenhalve8000 + 3200 = 11200, half is 5600
    From 8000 million at the end of the fourth hour: 5600, 4400 and 3800 million at the ends of the hours before.
  3. 3.(a) 3800 + 32002 = 3500: the culture held 3500 million cells at the start. Check forward: 3500 → 7000 − 3200 = 3800 → 4400 → 5600 → 8000.

    Million cells at the end of each hour, after the harveststarthour 1hour 2hour 3hour 435003800440056008000One hour back: add the 3200 harvested, then halve8000 + 3200 = 11200, half is 56003800 + 3200 = 7000, half is 3500 at the start
    Million cells at the end of each hour, after theharveststarthour 1hour 2hour 3hour 435003800440056008000One hour back: add the 3200 harvested, thenhalve8000 + 3200 = 11200, half is 56003800 + 3200 = 7000, half is 3500 at the start
    (a) 3800 + 32002 = 3500 million cells at the start.
  4. 4.For (b), the goal is that the sixth harvest can take the full 3200 million, so after it the count is at least 0. Run the same rule back: at least 0 + 32002 = 1600 at the end of the fifth hour, then at least 2400, 2800, 3000 and 3100 at the end of the fourth, third, second and first hours.

    At least this many million cells at the end of each hourstart123456310030002800240016000The sixth harvest leaves at least 0Each hour back: add 3200, then halve
    At least this many million cells at the end of eachhourstart123456310030002800240016000The sixth harvest leaves at least 0Each hour back: add 3200, then halve
    After the sixth harvest the count is at least 0, so at least 1600 million at the end of the fifth hour, and so on back.
  5. 5.(b) One more hour back gives at least 3100 + 32002 = 3150: the batch must start with at least 3150 million cells. Check forward: 3150 → 3100 → 3000 → 2800 → 2400 → 1600 → 0, six full harvests, the last one emptying the bioreactor. A start of fewer cells leaves every count lower, so the sixth harvest would be short.

    At least this many million cells at the end of each hourstart1234563150310030002800240016000The sixth harvest leaves at least 0Each hour back: add 3200, then halve3100 + 3200 = 6300, half is 3150 at the start
    At least this many million cells at the end of eachhourstart1234563150310030002800240016000The sixth harvest leaves at least 0Each hour back: add 3200, then halve3100 + 3200 = 6300, half is 3150 at the start
    (b) At least 3100 + 32002 = 3150 million cells at the start.

Answer: (a) 3500 million cells; (b) 3150 million cells

Common mistakes

  • Undoing the moves in the order they happened, halving first and then adding 3200. From 8000 that gives 7200 at the end of the third hour, which is wrong: the harvest was the last thing done in the hour, so it is the first thing to undo.
  • In (b), asking for 3200 million cells at the START of each hour. The harvest comes after the cells double, so the count at the end of the fifth hour needs to be only 1600 million, and demanding 3200 gives a starting number that is far too large.

More problem solving problems, worked step by step →

Worked example: A Thanksgiving Dinner to Be Served at 6:00 pm, and When the Turkey and the Gravy Must Start

Question A family will serve Thanksgiving dinner at 6:00 pm. The turkey is prepared (30 minutes), roasted (3 hours), rested (30 minutes) and carved (15 minutes), in that order, each task starting when the one before it ends or later. The gravy takes 15 minutes and is made from the juices in the roasting pan, so it can start only once the roasting has finished. Several cooks share the work, so tasks that do not depend on each other can run at the same time, and everything must be finished by 6:00 pm. (a) What is the latest time the turkey's preparation can start, and how many minutes before 6:00 pm is that? (b) The turkey starts at that latest time. What is the latest time the gravy can start, and for how many minutes can it wait after the roasting ends?

  1. 1.Start from the goal. Carving takes 15 minutes and must end by 6:00 pm, so it starts by 5:45 pm at the latest. The turkey rests for 30 minutes before carving, so resting starts by 5:15 pm.

    Rest5:15 to 5:45Carve5:45 to 6:00Times are pm, fixed back from dinner at 6:00
    Rest5:15 to 5:45Carve5:45 to 6:00Times are pm, fixed back from dinner at 6:00
    Carving ends at 6:00 pm, so it starts by 5:45 pm, and resting starts by 5:15 pm.
  2. 2.The gravy takes 15 minutes and must also be ready at 6:00 pm, so it starts by 5:45 pm at the latest.

    Rest5:15 to 5:45Carve5:45 to 6:00Gravystart by 5:45Times are pm, fixed back from dinner at 6:00
    Rest5:15 to 5:45Carve5:45 to 6:00Gravystart by 5:45Times are pm, fixed back from dinner at 6:00
    The gravy must be ready at 6:00 pm, so it starts by 5:45 pm.
  3. 3.Two tasks wait on the roasting: resting, which must start by 5:15 pm, and the gravy, which must start by 5:45 pm. The roasting must finish in time for both, so it finishes by the earlier time, 5:15 pm, and three hours of roasting start by 2:15 pm.

    Roastroast for 3 hours2:15 to 5:15Rest5:15 to 5:45Carve5:45 to 6:00Gravystart by 5:45Resting starts by 5:15 and the gravy by 5:45: the roasting endsby 5:15
    Roastroast for 3 hours2:15 to 5:15Rest5:15 to 5:45Carve5:45 to 6:00Gravystart by 5:45Resting starts by 5:15 and the gravy by 5:45: theroasting ends by 5:15
    The roasting must end by the earlier of 5:15 pm and 5:45 pm, so it runs from 2:15 pm to 5:15 pm.
  4. 4.(a) Preparation takes 30 minutes before the roasting, so it starts by 1:45 pm at the latest. That is 255 minutes before 6:00 pm. Check: 30 + 180 + 30 + 15 = 255 minutes.

    Prepare1:45 to 2:15Roastroast for 3 hours2:15 to 5:15Rest5:15 to 5:45Carve5:45 to 6:00Gravystart by 5:45Start by 1:45 pm: 255 minutes before dinner
    Prepare1:45 to 2:15Roastroast for 3 hours2:15 to 5:15Rest5:15 to 5:45Carve5:45 to 6:00Gravystart by 5:45Start by 1:45 pm: 255 minutes before dinner
    (a) Preparation starts by 1:45 pm, which is 255 minutes before 6:00 pm.
  5. 5.(b) Starting at 1:45 pm, the roasting ends at 5:15 pm, and the juices are ready then. The gravy can start at any time from 5:15 pm to 5:45 pm, so its latest start is 5:45 pm and it can wait up to 30 minutes after the roasting ends. Check: 5:45 pm plus 15 minutes is 6:00 pm.

    Prepare1:45 to 2:15Roastroast for 3 hours2:15 to 5:15Rest5:15 to 5:45Carve5:45 to 6:00Gravystart 5:15 to 5:45The gravy can wait up to 30 minutes after the roasting ends
    Prepare1:45 to 2:15Roastroast for 3 hours2:15 to 5:15Rest5:15 to 5:45Carve5:45 to 6:00Gravystart 5:15 to 5:45The gravy can wait up to 30 minutes after theroasting ends
    (b) The gravy can start at any time from 5:15 pm to 5:45 pm: it can wait up to 30 minutes.

Answer: (a) 1:45 pm, which is 255 minutes before 6:00 pm; (b) 5:45 pm, so the gravy can wait up to 30 minutes after the roasting ends at 5:15 pm

Common mistakes

  • Letting the gravy set the roasting's deadline, so that the roasting ends at 5:45 pm. The resting also waits on the roasting and must start by 5:15 pm, so the roasting has to meet the earlier of the two times.
  • Adding up every task, gravy included: 30 + 180 + 30 + 15 + 15 = 270 minutes, a start at 1:30 pm. The gravy runs at the same time as the resting and carving, so it adds nothing to the time before dinner.

More problem solving problems, worked step by step →

Practice Working Backwards from the Goal in the app