In the cliff-walking gridworld (reward per step, for stepping off the cliff), an -greedy SARSA agent learns a safe path away from the edge, while Q-learning learns the path along the edge yet earns less reward per episode during training. Why?
Reinforcement learning, Temporal-difference learning
Level L3 Intermediate. Length Medium. Nature Th+Mat Both.
What's being asked
Whether you understand the practical consequence of on-policy versus off-policy targets when exploration is never switched off.
Key idea
SARSA's target uses the next -greedy action, so it learns , the value of the exploring policy, which includes the risk of random steps off the cliff. Q-learning's target learns , the value of acting greedily afterwards, which ignores that risk.
Steps
- Write both updates side by side and point to the only difference: with versus . Here is the -greedy policy: it takes the best-looking action with probability and a random action otherwise.
- State what each converges to with fixed : SARSA to , Q-learning to .
- Apply it to the cliff: next to the edge, a random exploratory action can step off for . SARSA's values near the edge include this risk, so the longer, safer path scores higher.
- Q-learning's values assume greedy play afterwards, so the shortest path along the edge (13 steps on the standard grid) is optimal. But the agent still explores while following it and sometimes falls, so its online return is worse.
- Conclude: if over time, both converge to the optimal path. SARSA is preferable when mistakes made during learning are costly, as with a real robot.
Common mistakes
- Saying Q-learning "learns the wrong answer". It learns the optimal greedy policy, which really is the edge path.
- Forgetting that the comparison is about online return with exploration still on.
- Calling SARSA off-policy because it uses -greedy actions. It is on-policy because it evaluates the same policy that generates the data.
How long your answer should be
2–3 minutes: the two targets, one paragraph of reasoning, one sentence on decaying .
Last checked on 4 December 2026.
Read this
- Sutton and Barto, Reinforcement Learning: An Introduction (2nd ed.), Example 6.6: Free PDF. Example 6.6, Cliff Walking (p. 132), with Sections 6.4–6.5: the original figure of the safe and optimal paths and the online-reward curves for Sarsa and Q-learning.
- David Silver, UCL RL Course, Lecture 5: Model-Free Control: Slide 40, Cliff Walking Example, after the Sarsa and Q-learning slides: a compact recap of the same comparison.
- NPTEL: Reinforcement Learning (IIT Madras, Prof. Balaraman Ravindran): Week 6, TD(0) Control and Q-Learning, which cover SARSA and Q-learning as on-policy and off-policy control.
Previous in Reinforcement learning: Compare Monte Carlo and TD(0) value estimation in terms of bias and variance. Given eight episodes, one (A, 0, B, 0), six (B, 1) and one (B, 0), with , what do batch Monte Carlo and batch TD(0) give for and ?
Next in Reinforcement learning: Write PPO's clipped surrogate objective. With , evaluate the per-sample objective, and say whether it has a non-zero gradient, when (a) , ; (b) , ; (c) , . What is the clipping for?