Worked examples — Markov Decision Processes (MDP)
We use only ideas already built in the parent: a state (a situation), an action (a choice), the transition probability (chance of landing in ), the reward (immediate payoff), the discount (how much we shrink future rewards), the value (expected total discounted reward from under policy ), and the action-value . See 5.1.03-Policy-and-Value-Functions and 5.1.04-Bellman-Equations if any symbol feels shaky.
The scenario matrix
Every MDP exercise you'll meet is one (or a blend) of these cells. Each worked example below is tagged with the cell it covers.
| Cell | What makes it tricky | Example |
|---|---|---|
| A. Deterministic chain | probability is always 1, pure discounting | Ex 1 |
| B. Self-loop / terminal | infinite geometric series, | Ex 2 |
| C. Stochastic transition | must average over outcomes | Ex 3 |
| D. (myopic) | only immediate reward matters | Ex 4 |
| E. (far-sighted) | limiting/divergence behaviour | Ex 4 |
| F. Action choice (optimality) | over actions, policy | Ex 5 |
| G. Negative reward / penalty | signs must be handled carefully | Ex 6 |
| H. Real-world word problem | translate English → tuple | Ex 7 |
| I. Exam twist | coupled equations, solve simultaneously | Ex 8 |
Recall Quick self-test before diving in
What does multiply? ::: The reward received steps in the future, shrinking far rewards. Why must appear on both sides of a Bellman equation? ::: Because value from a state includes the value of the state you move to — it is self-referential (recursive).
Example 1 — Deterministic chain (Cell A)
Forecast: you're 3 steps from a . Guess whether it's above or below .
The figure below draws the corridor. Textual description of the figure: four rounded boxes sit in a horizontal row, left to right, labelled , , (all lavender) and (mint, the goal). Three coral arrows point rightward, one from each box to its neighbour, each tagged "right" — these are the deterministic actions. The rightmost coral arrow, entering , carries the extra tag "+10 on entry" above it. Under each box its computed value is written: , , , and "goal +10". The reward tag sits on the arrow into , not inside — that is the " on entry" detail Step 1 hinges on.

Step 1 — Write the terminal value. is terminal, so no future reward accumulates from it: . Why this step? A terminal state has no "after", so its ongoing value is zero. The is collected entering it, on the previous transition (the labelled coral arrow in the figure).
Step 2 — Value of . From , going right lands in (prob 1), collecting reward : Why this step? This is the Bellman expectation equation with a single certain outcome, so the sum has one term.
Step 3 — Back up the chain. Each earlier state just discounts the next (follow the values under the boxes leftward): Why this step? Each step adds no reward but multiplies by , so being one step farther halves the value.
Verify: the enters the return two discount factors deep (it is applied once as we leave into , again from into ), so is discounted by : . ✓ (Below , as forecast.)
Example 2 — Self-loop terminal (Cell B)
Forecast: an infinite stream of 's, shrunk by each step. Bigger or smaller than ?
Step 1 — Set up the self-referential equation. The self-loop means the "next state" is again: Why this step? When a state loops to itself, its own value appears on both sides — this is the recursive heart of Bellman.
Step 2 — Solve algebraically. Why this step? This is exactly the geometric-series sum . The algebra and the series agree.
Step 3 — Back-substitute. The corridor needs two -reward steps to reach the paying state :
Verify: . ✓ (Equals at the goal — the "keeps paying" version, unlike Ex 1's one-shot .)
Example 3 — Stochastic transition (Cell C)
Forecast: slipping wastes time. Higher or lower than the no-slip value of ?
Step 1 — Average over both outcomes. The Bellman sum now has two terms weighted by probability: Why this step? Stochastic transitions mean expectation = probability-weighted average of "reward + discounted next value" across every reachable .
Step 2 — Collect the terms. Why this step? Same self-reference trick as Ex 2: the slip probability puts on both sides.
Verify: . ✓ Slipping strictly lowers value — uncertainty is costly.
Example 4 — Discount extremes (Cells D & E)
Forecast: myopic sees only "now". Far-sighted sees a huge future. Guess both magnitudes.
Step 1 — . Why this step? With the future term vanishes entirely — the agent is completely short-sighted and values only the immediate reward.
Step 2 — . Why this step? The geometric bound blows up as approaches — a patient agent counts far rewards almost fully.
Step 3 — The limit . Why this step? At exactly an infinite stream of positive rewards diverges — this is precisely why the parent required , strictly below , for infinite-horizon tasks.
Verify: ; ; and the series diverges at . ✓ All three consistent with (which gives at too).
Example 5 — Action choice & optimal policy (Cell F)
Forecast: the risky action's average outcome — above or below the safe ?
Textual description of the figure: (lavender box) sits on the left. Three arrows leave it. A mint arrow labelled "a1 safe +5" goes up-right to (mint box) — this is the deterministic safe action. A butter (pale-yellow) arrow labelled "a2 0.5 +20" goes right to (butter box), and a coral arrow labelled "a2 0.5 -10" goes down-right to (coral box) — these two are the two random branches of the single risky action , each tagged with its probability and reward. Beside each destination box its given optimal value is printed: at , at , at . A summary caption near reads "Q(a1)=55, Q(a2)=60, pick a2".

Step 1 — for the safe action. Why this step? = immediate reward + discounted optimal future value of where you land (safe action lands in for sure, following the mint arrow).
Step 2 — for the risky action (average two branches). Why this step? Expectation over the stochastic outcomes (butter and coral arrows); note the penalty is handled just like any reward, keeping its sign.
Step 3 — Take the max (Bellman optimality). Why this step? The optimal value picks the best value (); the optimal policy picks the action achieving it ().
Verify: , so risky wins. ✓ The good branch () outweighs the bad () on average.
Example 6 — Negative rewards (Cell G)
Forecast: the pit repeats its penalty. How negative does that get?
Step 1 — Value of the pit (self-loop, negative). The pit has only one action (fall forever), so its optimal value is forced: Why this step? Same machinery — negative just gives a negative value; the algebra is identical.
Step 2 — Q-values. Why this step? "Down" earns nothing on the transition then inherits the pit's value ; "up" collects into a terminal ().
Step 3 — Optimal choice.
Verify: ✓, and ✓ — avoid the pit.
Example 7 — Real-world word problem (Cell H)
Forecast: cleaning pays but risks death; recharging is safe but idle. Which wins?
Step 1 — Identify the tuple formally.
- .
- .
- Transition function :
- , ,
- .
- Reward function (payoff on the specific transition):
- , ,
- .
- ; and the given terminal values , .
Why this step? Every word problem must first be pinned to the full tuple — especially writing with all three arguments so each English payoff maps to a specific transition — before any equation is legal. This mirrors 5.1.01-Reinforcement-Learning-Problem-Formulation.
Step 2 — for "recharge". Why this step? Recharge is deterministic (prob 1) into terminal High, so the Bellman sum has a single term: immediate plus discounted terminal value .
Step 3 — for "clean" (Dead is terminal, ; clean can loop back to Low, so its value recurs): Assume the optimal action in Low is "clean" so : Why this step? Clean can loop back to Low, so its own value appears on both sides — solve the fixed-point equation exactly as in the self-loop examples.
Step 4 — Compare. , so . Why this step? The optimal policy in a state is the over its actions' Q-values; recharge has the higher Q, so it is chosen (and the "clean" assumption made in Step 3 turns out sub-optimal — that is fine, we compared both).
Verify: solving gives ✓; and ✓ — recharge, the death risk sinks cleaning.
Example 8 — Exam twist: coupled equations (Cell I)
Forecast: the values feed each other in a loop. Two unknowns, two equations.
Step 1 — Write both Bellman equations. Why this step? Each state's value depends on the other's value — a coupled linear system, exactly what 5.2.01-Dynamic-Programming-inRL solves iteratively.
Step 2 — Substitute. Put the expression for into the first equation to eliminate one unknown: Why this step? Substitution collapses two equations into one equation in a single unknown, which we can then solve by ordinary algebra.
Step 3 — Recover . Why this step? Back-substitution once one unknown is known.
Verify: plug back: ✓ and ✓. Both equations satisfied simultaneously.
Recall Which cell was hardest for you?
Cell G (negative self-loop) answer ::: ; sign flows straight through the geometric sum. Cell I (coupled) answer ::: ; substitute then solve.