In state s the agent takes action a with Q(s,a)=1, gets reward 0 and lands in s′, where Q(s′,a1)=3 and Q(s′,a2)=5. The ε-greedy policy then picks the exploratory action a1. With α=0.5 and γ=0.9, compute the new Q(s,a) under SARSA and under Q-learning. Why do they differ?

Reinforcement learning, Temporal-difference learning
Level L2 Elementary. Length Short. Nature Mat Mathematical.

What's being asked

Whether you know that SARSA's target uses the next action actually taken, while Q-learning's uses the best next action.

Key idea

SARSA is on-policy: Q(s,a)←Q(s,a)+α[r+γQ(s′,a′)−Q(s,a)], with a′ the action actually chosen. Q-learning replaces Q(s′,a′) by max⁡a′Q(s′,a′).

Steps

  1. SARSA target: r+γQ(s′,a1)=0+0.9×3=2.7, because a1 was the action chosen.
  2. SARSA update: Q(s,a)=1+0.5 (2.7−1)=1.85.
  3. Q-learning target: r+γmax⁡a′Q(s′,a′)=0+0.9×5=4.5.
  4. Q-learning update: Q(s,a)=1+0.5 (4.5−1)=2.75.
  5. Explain the difference. SARSA evaluates the exploring policy it is following, so exploratory slips lower its values. Q-learning evaluates the greedy policy, ignoring what the behaviour policy does next.

Common mistakes

How long your answer should be

5–6 lines.

Last checked on 4 December 2026.

Read this

Previous in Reinforcement learning: In TD(0), the current estimate is V(s)=0.5. The agent moves from s to s′ with reward r=1, and V(s′)=2. With γ=0.9 and α=0.1, what are the TD target, the TD error and the updated V(s)?
Next in Reinforcement learning: A corridor has three non-terminal cells 1, 2, 3 in a row, with a terminal cell L to the left of cell 1 and a terminal cell R to the right of cell 3. The policy moves left or right with probability 0.5 each. Moving into R gives reward +1, and every other move gives reward 0. With γ=1 and V0=0, compute V1,V2,V3 (synchronous sweeps) for cells 1, 2, 3. What do the values converge to?