2.9 Multi-stage problems and dynamic programming — Practise
Work independently. The questions and answers are shown together at the end.
Show the value at every state, stage by stage from the last one backwards. A single final number with no table is worth few marks.
- A network has four stages. Stage 1 is ; stage 2 is ; stage 3 is ; stage 4 is . The edges are , , , , , , , . Work backwards and find the least cost from to .
- For the same network, find the least cost from to , and from to .
- For the same network, find the least cost from to and from to .
- For the same network, find the least total cost from to and write down the route.
- In a dynamic programming problem, state what a stage and a state are.
- Explain why backward recursion starts at the last stage.
- On that network, a student at takes the cheaper first edge, , and then has to pay to finish, for a total of 10. What does this show?
Answers and concise solutions
1. Show the answer
1. Least cost from D to F
Answer: From there is only one edge forward, , so the least cost from to is . Backward recursion always starts at the last stage, where the value is known directly.
2. Show the answer
2. Cost from E, then from D
Answer: From : only , so the least cost is . From : only , so the least cost is . Stage 3 is where the recursion begins.
3. Show the answer
3. Cost from B, then from C
Answer:
From : either at , or at . The least is , through . From : either at , or at . The least is , through .
4. Show the answer
4. Least total cost, then the route
Answer: From : either then more, at , or then more, at . The least total cost is , along : .
5. Show the answer
5. Stage and state
Answer:
A stage is one step in the sequence of decisions — in a staged network, which column you are in. A state is the situation you can be in at that stage — in a staged network, which vertex you are at. Dynamic programming works because the best decision from a state does not depend on how you reached it. That is what lets the recursion run backwards from the last stage, where the value is known, to the first.
6. Show the answer
6. Why it starts at the last stage
Answer:
At the last stage the answer is known without any decision: the cost from a final vertex to the destination is just the edge to the destination, or zero if you are already there. Working backwards, each earlier stage is then solved using the values already found for the stage after it. Every value is computed once and reused, which is what makes dynamic programming efficient — it never solves the same sub-problem twice.
7. Show the answer
7. What the greedy choice shows
Answer:
It shows that taking the cheapest edge at each step — the greedy choice — does not always give the best total. is cheaper than , but choosing it leaves only expensive ways to finish, for a total of . Choosing the more expensive gives the better total of . Dynamic programming avoids this by looking at the whole remaining problem at each stage, rather than only the next edge. That is why it needs the values from the later stages before it can decide.