Exercises — Q-learning algorithm
The figure below turns that rule into a single picture — read it left to right before touching any exercise.

Level 1 — Recognition
Exercise 1.1
Here means the transition probability: the chance that, taking action in state , the environment sends you to state (see Markov Decision Processes). For each property, name it: (a) Q-learning does not need to know . (b) Q-learning can follow an -greedy policy yet still learn the optimal one. (c) Q-learning updates one estimate using another estimate.
Recall Solution
(a) Model-free — it never needs the transition probabilities ; it learns straight from sampled experience. (b) Off-policy — the behaviour policy (exploring) differs from the target policy (greedy/optimal) baked in by the . (c) Temporal-difference / bootstrapping.
Exercise 1.2
In the update rule, point to (a) the TD target and (b) the TD error, and (c) say what equals and why.
Recall Solution
(a) TD target . (b) TD error . (c) — once the episode ends there is no future reward to collect, so the "best future value" term is exactly zero.
Level 2 — Application
Exercise 2.1
. You take , get , land in where . With , compute the new .
Recall Solution
TD target . TD error .
Exercise 2.2
Late in training, , , current , , next state is the goal with . With , compute the update.
Recall Solution
Target . Error . This is reward propagating backward: the goal's high value now leaks one step upstream. The figure below is drawn with these exact numbers — the teal dot sits at the old , the orange dot at the target , and the plum dot at the new , only a tenth of the way across because .

Exercise 2.3
Same state twice in a row with . . First transition , . Then the update lands you back at the same and you observe , again. Give after both updates.
Recall Solution
Update 1: target , error , . Update 2: target , error , . Each pass closes half the remaining gap ().
Level 3 — Analysis
Exercise 3.1 (Off-policy vs on-policy)
State : optimal action with , suboptimal with . Exploration forces the agent to take , gets , next state has but the action SARSA would actually take next has value . With , compute the update for Q-learning and for SARSA, and explain the difference.
Recall Solution
Q-learning (uses ): target , error , SARSA (uses the actually chosen next action's value ): target , error , Difference: Q-learning bootstraps off the best possible future (), so it estimates the value under an optimal future even though it acted suboptimally. SARSA bootstraps off what it will really do next (), so it learns the value of its own exploratory policy. That is exactly the on-policy vs off-policy distinction.
Exercise 3.2 (Contraction / convergence rate)
Two pieces of notation first. The symbol is the supremum norm — the single biggest absolute value takes over all its inputs; here is "the largest gap between the two Q-tables over every state-action pair." The symbol is the Bellman optimality operator: a machine that eats a Q-table and returns an improved one, Here the expectation is taken over the next state drawn from the transition distribution — that is what makes it a well-defined average and not just a single sample. It is one full "sweep" of the update applied everywhere at once.
Why is a contraction (why matters)? Take any two Q-tables . For a fixed the immediate-reward terms cancel, leaving Two facts finish it: (i) (the biggest-gap bound), and (ii) (probabilities sum to one). So the whole right side is . Taking the max over all gives Because , each sweep strictly shrinks the biggest gap, so repeated sweeps drive any two tables together to one unique fixed point (this is the Banach fixed-point idea). If the factor is and nothing is guaranteed to shrink — that is exactly why is required.
Question. If the initial max error is and , how many exact Bellman sweeps guarantee the max error drops below ?
Recall Solution
After sweeps the error is at most . Solve : So sweeps suffice. This is why is required: it forces the map to shrink distances by a fixed factor, guaranteeing a unique fixed point . See Bellman Equations and Temporal Difference Learning.
Exercise 3.3 (Learning-rate schedule)
Which of these schedules satisfy the Robbins–Monro conditions and ? (a) , (b) , (c) (constant).
Recall Solution
(a) ✓ and ✓ → valid. (b) ✓ but ✗ → fails the square-summable part. (c) ✓ but ✗ → fails; a constant never converges to the exact , it keeps jittering. Only (a) satisfies both.
Level 4 — Synthesis
Exercise 4.1 (Maximization bias — quantify it)
Two next-state actions each have true value . Your unbiased estimates are noisy: sample estimates come out and . (a) What does single-Q-learning use as the future value via ? (b) What is the true best future value? (c) Explain the sign of the bias, then state how Double Q-learning removes it.
Recall Solution
(a) . (b) True best future value . (c) The estimate () overshoots the truth () — a positive maximization bias, because taking a over noisy numbers systematically grabs the luckily-overestimated one. Double Q-learning fix: keep two independent tables . Pick the action with one, ; evaluate it with the other, target . Because selection and evaluation use independent noise, the lucky pick in is not systematically lucky in , so the bias cancels in expectation.
Exercise 4.2 (Backward reward propagation, multi-step)
A deterministic chain . Each step except reaching the goal gives . . There is a single move-forward action at each state, so we write as shorthand for — the action argument is dropped only because there is exactly one action. Compute at convergence.
Recall Solution
Work backward. At the next state is the goal (terminal, value after), reward is : At : reward , best next value is : At : So — the reward decays by each step further from the goal. This is the Markov Decision Processes value smearing across states, and it is what Monte Carlo RL would also arrive at (via full returns instead of bootstrapping).
Exercise 4.3 (Design -decay)
You want where is the episode number (1-indexed). (a) Give at episodes 1, 10, 100. (b) Over episodes , does the total exploration diverge, guaranteeing "infinitely often" visits if continued forever?
Recall Solution
(a) . (b) is the harmonic series , so exploration never fully dies out in the summed sense — this supports the requirement that all be visited infinitely often. See Exploration-Exploitation Trade-off.
Level 5 — Mastery
Exercise 5.1 (Full single episode, from scratch)
-state chain: states ; single action each moves right. Start at . gives ; gives (goal terminal). , all init . Run two episodes and give after each.
Recall Solution
Episode 1. Step : target ; . Step : target ; . After ep 1: . Episode 2. Step : target ; . Step : target ; . After ep 2: . Notice the reward from the goal took one full episode to reach : was stuck at during ep 1 because was still when updated. Bootstrapping propagates value one hop per episode.
Exercise 5.2 (Off-policy convergence target)
In the -state chain of 5.1 but with , what are the exact converged values ?
Recall Solution
Start from , whose next state is the terminal goal (value afterwards) with reward : Then , whose reward is and whose best next value is : So . Every finite run of 5.1's updates crawls toward these fixed points; the contraction (Ex 3.2) guarantees it.
Exercise 5.3 (Stochastic reward — why )
Taking action in (terminal next) yields reward with prob and with prob . (a) What is ? (b) If , what does equal right after any single update? (c) Why does small help?
Recall Solution
(a) . (b) With the update replaces: , so is or depending on the last sample — it never settles, pure high variance. (c) Small makes each update a running average, so noisy samples average toward the true mean . This is why is only safe in deterministic worlds.
Exercise 5.4 (Compare families)
For each task pick the most natural algorithm from the list and give a one-line reason: (a) huge image-state Atari game, (b) needing an on-policy value that respects your own exploration risk, (c) continuous action steering of a robot arm.
Recall Solution
(a) Deep Q-Networks (DQN) — states are raw pixels, so tabular Q is impossible; use Function Approximation with a neural net (e.g. Atari Game Playing). (b) SARSA — on-policy, so its values include the cost of exploratory mistakes. (c) Policy Gradient Methods — continuous actions make intractable; parameterise the policy directly (e.g. Robot Control). Q-learning's needs a finite/enumerable action set.