Video 2, chapter 6

The Bridge and Torch

How the bridge and torch problem with walkers taking 1, 2, 5 and 10 minutes is solved in 17 minutes, why a greedy strategy takes 19, and how a case argument and an exhaustive search prove the schedule optimal.

  • Video 2, chapter 6
  • Plan the moves

Four people must cross a narrow bridge at night with a single torch. They take 1, 2, 5 and 10 minutes to cross, at most two can be on the bridge at once, and a pair walks at the pace of the slower person. Letting the fastest walker escort everyone across takes 19 minutes. Can all four be across in 17? This page finds a 17-minute schedule, shows why the obvious plans fall short, and proves that no schedule is faster.

Key terms

Bridge and torch problem

Definition In the bridge and torch problem, four walkers who take 11, 22, 55 and 1010 minutes to cross a bridge start together on one side at night with one torch. Call them walker 1, walker 2, walker 5 and walker 10, after their times. At most two people may be on the bridge at once, and nobody may cross without the torch, so every crossing carries the torch and it gets back to the starting side only when someone carries it back. A walker crossing alone takes their own time, and two walkers crossing together take the time of the slower one. Since there is one torch, the crossings happen one after another, and the total time is the sum of the times of all the crossings. The goal is to get all four to the far side in the least total time. The least total is 1717 minutes, reached when walkers 1 and 2 cross, walker 1 returns, walkers 5 and 10 cross, walker 2 returns, and walkers 1 and 2 cross again. No schedule takes less than 1717 minutes.

In plain words Walker 5 can go along with walker 10 at no extra cost, provided that a fast walker is already waiting on the far side to bring the torch back. As in The River-Crossing Shuttle, the trick is to place someone across in advance for the return trip.

Example The table follows the 17-minute schedule.

CrossingWho crossesMinutesRunning total
1walkers 1 and 2, forward2222
2walker 1, back1133
3walkers 5 and 10, forward10101313
4walker 2, back221515
5walkers 1 and 2, forward221717

Every crossing carries the torch from the side where it is. After crossing 2, walker 2 waits on the far side, and that is what lets walker 2 bring the torch back after the slow pair arrives.

Greedy strategy

Definition A greedy strategy builds a plan one step at a time and at each step takes the option that looks best for that step alone, by a fixed rule, without looking ahead to later steps. Greedy strategies are easy to follow and sometimes give the best plan, but a choice that is cheapest now can force expensive steps later, so in general a greedy plan need not be optimal.

In plain words Do whatever is cheapest right now and never reconsider.

Example For the bridge, a natural greedy rule sends the two fastest people on the starting side across and has the fastest person on the far side bring the torch back. It gives walkers 1 and 2 for 22 minutes, walker 1 back for 11, walkers 1 and 5 for 55, walker 1 back for 11 and walkers 1 and 10 for 1010, which totals 1919 minutes. Letting walker 1 escort walker 10, then walker 5, then walker 2, bringing the torch back each time, also gives

10+1+5+1+2=19.10 + 1 + 5 + 1 + 2 = 19.

Both plans pay separately for the slow crossings of walkers 5 and 10. The 17-minute schedule spends 1414 minutes on its three forward crossings instead of 1717, and 33 minutes on its returns instead of 22, so it saves 22 minutes in all.

Optimal schedule

Definition A schedule is a sequence of legal crossings that takes everyone from the starting side to the far side. A schedule is optimal if no legal schedule has a smaller total time. Proving that a schedule is optimal means ruling out every other schedule, including long ones that send people back and forth, either by an argument that covers all of them or by an exhaustive search. For four walkers with positive times a≤b≤c≤da \le b \le c \le d, the optimal total is the smaller of the escort total and the shuttle total,

2a+b+c+d,a+3b+d.\begin{gathered} 2a + b + c + d, \\[0.4em] a + 3b + d. \end{gathered}

The shuttle is faster exactly when 2b<a+c2b < a + c, the two plans tie when 2b=a+c2b = a + c, and otherwise the escort is faster. For the times 11, 22, 55 and 1010 the totals are 1919 and 1717.

In plain words Optimal means that nothing is faster. Showing that takes an argument about every possible schedule, not just the ones that come to mind.

Example Here is why no schedule for 11, 22, 55 and 1010 beats 1717 minutes. A forward crossing carries at most two people and a return carries at least one. With ff forward crossings there are f−1f - 1 returns, so at most 2f−(f−1)=f+12f - (f - 1) = f + 1 people end up across. All 44 must end up across, so f≥3f \ge 3, and every schedule has at least three forward crossings and two returns.

Suppose first that walkers 5 and 10 never cross forward together. Then their forward crossings are different and take at least 1010 and 55 minutes. With exactly three forward crossings, at most 66 people go forward and at least 22 come back, and the difference must be 44, so all three forward crossings carry pairs and both returns carry single walkers. Then the third forward crossing takes at least 22 minutes and each return at least 11, for a total of at least 10+5+2+1+1=1910 + 5 + 2 + 1 + 1 = 19. With four or more forward crossings there are at least three returns, and the total is at least 10+5+1+1+3=2010 + 5 + 1 + 1 + 3 = 20.

Suppose instead that walkers 5 and 10 cross forward together, which takes 1010 minutes. If either of them ever goes back, that return takes at least 55 minutes, and since there are at least two other forward crossings and at least one other return, each taking at least 11 minute, the total is at least 10+5+3=1810 + 5 + 3 = 18. Otherwise walkers 5 and 10 never go back, so each of them crosses only once, in the joint crossing, and every other crossing uses only walkers 1 and 2. Their joint crossing is not the last one, because walkers 1 and 2 would then have to be across already, while the return just before it, which brought the torch back, was made by one of them. So a return follows it, made by walker 1 or walker 2 from the far side. The joint crossing is not the first one either, since walker 5 or walker 10 would then have to make the return after it. So a return also comes just before it. Whoever makes the return after the joint crossing was on the far side during it, and whoever made the return before it was on the starting side, so these two returns are made by different walkers, one by walker 1 and the other by walker 2. Together they take at least 1+2=31 + 2 = 3 minutes. Walker 2 has to cross forward before making a return and again after it, and each of these two forward crossings takes at least 22 minutes. This case therefore takes at least

10+3+2+2=1710 + 3 + 2 + 2 = 17

minutes. In every case the total is at least 1717, and the schedule above takes exactly 1717, so it is optimal.

Definition An exhaustive search solves a problem by examining every candidate in a finite list that is known to contain a best answer, so that the best candidate found is the best overall. For a puzzle the list can be all of its states together with the legal moves between them. The search is valid only if the list really covers every possibility, so when a puzzle allows plans of any length, one needs a reason why a finite list is enough.

In plain words Check every possibility, leave nothing out, and the best one found is the best there is.

Example Each walker is on one side or the other and so is the torch, so the bridge has 24⋅2=322^4 \cdot 2 = 32 states. A schedule can be made as long as you like by sending people back and forth, but if a schedule comes back to a state it has visited before, deleting the crossings in between gives a legal schedule that is faster, because every crossing takes at least a minute. So an optimal schedule never repeats a state, and there are only finitely many schedules of that kind. For these four walkers there are 73,64473{,}644 of them, with between 55 and 1717 crossings. Checking every one shows that exactly two take 1717 minutes, none takes 1818 and six take 1919. A computer usually skips the listing and finds the cheapest path through the 3232 states directly, which gives the same 1717.

The schedules with exactly five crossings can be checked by hand. Each of them sends a pair forward three times and a single walker back twice, so there are 6⋅2⋅3⋅3=1086 \cdot 2 \cdot 3 \cdot 3 = 108 of them, from 66 choices of the first pair, 22 of the first returner, 33 of the second pair and 33 of the second returner, after which the last pair is fixed. The same two schedules are the only ones among them that take 1717 minutes.

Check yourself

  1. The 17-minute schedule uses walker 1 for the first return and walker 2 for the second. Find a schedule with the returns the other way round and find its total time.
Show the answer

Walkers 1 and 2 cross in 22 minutes, and walker 2 brings the torch back in 22. Walkers 5 and 10 cross in 1010, joining walker 1, who has been waiting on the far side, and walker 1 brings the torch back in 11. Walkers 1 and 2 cross together in 22. The total is

2+2+10+1+2=172 + 2 + 10 + 1 + 2 = 17

minutes, so this schedule is optimal too. By the exhaustive search, these two schedules are the only optimal ones.

  1. Replace walker 2 by a walker who takes 44 minutes, so the times are 11, 44, 55 and 1010. Which plan is faster now, the escort or the shuttle, and what is the least total time?
Show the answer

The escort plan takes 10+1+5+1+4=2110 + 1 + 5 + 1 + 4 = 21 minutes. The shuttle plan takes 4+1+10+4+4=234 + 1 + 10 + 4 + 4 = 23 minutes, because the second walker now makes a slow return and crosses forward twice. By the rule for four walkers the least total is the smaller one, 2121 minutes. The test 2b<a+c2b < a + c now reads 8<68 < 6, which is false, so the shuttle no longer helps. Here the greedy rule described above is optimal, since it also takes 4+1+5+1+10=214 + 1 + 5 + 1 + 10 = 21 minutes. More generally, keep the other times at 11, 55 and 1010 and let the replacement walker take bb minutes with 1≤b≤51 \le b \le 5, so that it stays second fastest. The test reads 2b<62b < 6, so the shuttle wins when b<3b < 3, the two plans tie at 2020 minutes when b=3b = 3, and the escort wins when b>3b > 3.

  1. Extend the puzzle with a fifth walker who takes 2020 minutes, so the times are 11, 22, 55, 1010 and 2020. Find a schedule that takes 3333 minutes and compare it with the greedy rule.
Show the answer

Use the shuttle for the two slowest walkers first. Walkers 1 and 2 cross in 22 minutes, walker 1 returns in 11, walkers 10 and 20 cross in 2020, and walker 2 returns in 22. After these 2525 minutes walkers 10 and 20 are across, and walkers 1, 2 and 5 are on the starting side with the torch. Then walkers 1 and 5 cross in 55, walker 1 returns in 11, and walkers 1 and 2 cross in 22, which adds 88 minutes. The total is

25+8=3325 + 8 = 33

minutes. The greedy rule takes 2+1+5+1+10+1+20=402 + 1 + 5 + 1 + 10 + 1 + 20 = 40 minutes, and so does letting walker 1 escort everyone. An exhaustive search of the 25⋅2=642^5 \cdot 2 = 64 states confirms that no schedule for these five walkers takes less than 3333 minutes.