# Markov Decision Processes (MDP), Bellman Equations & Q-Learning (RL)
Exam: GATE Data Science & Artificial Intelligence (DA) (GATE DA)
Subject: Artificial Intelligence, Reasoning & RL
Canonical URL: https://gateandnet.com/exams/gate-da/artificial-intelligence/markov-decision-processes-bellman-and-q-learning

> Discounted Markov Decision Processes, Bellman Expectation vs Optimality equations, Value Iteration vs Policy Iteration convergence, and On-Policy SARSA vs Off-Policy Q-Learning.

## 1. Solving Known MDPs: Value Iteration vs Policy Iteration

An MDP is defined by $(S, A, T, R, \gamma)$ where $\gamma \in [0, 1)$ bounds infinite-horizon discounted return $G_t = \sum_{k=0}^\infty \gamma^k r_{t+k+1} \le \frac{R_{\max}}{1 - \gamma}$.

| Planning Method | Per-Iteration Step | Time per Iteration | Exact Convergence |
| :--- | :--- | :---: | :--- |
| **Value Iteration** | Non-linear Bellman optimality update $V_{k+1} \leftarrow \mathcal{B}^* V_k$ | $\mathcal{O}(|S|^2 \cdot |A|)$ | Asymptotic ($\|V_k - V^*\|_\infty \le \gamma^k \|V_0 - V^*\|_\infty$) |
| **Policy Iteration** | (1) Linear **Policy Evaluation** $(I - \gamma T^\pi)V^\pi = R^\pi$ + (2) Greedy **Policy Improvement** | $\mathcal{O}(|S|^3 + |S|^2|A|)$ | **Exact finite convergence** ($\le |A|^{|S|}$ policies) |

## 2. Model-Free Reinforcement Learning: SARSA vs Q-Learning

When transition probabilities $T(s,a,s')$ and rewards $R$ are **unknown**, the agent learns directly from experience tuples $(s, a, r, s', a')$:
- **SARSA (On-Policy TD Control):**
  $$Q(s, a) \leftarrow Q(s, a) + \alpha\big[r + \gamma Q(s', a') - Q(s, a)\big]$$
  Uses the **actual next action $a'$** chosen by the current $\epsilon$-greedy policy (in the classic *Cliff Walking* environment, SARSA learns the **safer upper path** away from the cliff because it accounts for $\epsilon$-random slips!).
- **Q-Learning (Off-Policy TD Control):**
  $$Q(s, a) \leftarrow Q(s, a) + \alpha\big[r + \gamma \max_{a'} Q(s', a') - Q(s, a)\big]$$
  Uses $\max_{a'} Q(s', a')$ regardless of exploratory behavior, converging directly to **$Q^*$** (the shortest optimal path right along the cliff edge!).

## Solved Practice Questions & PYQs

### [GATE DA RL | MCQ]
In tabular **Q-Learning** with learning rate $\alpha = 0.5$ and discount factor $\gamma = 0.8$, suppose $Q(s_1, a_1) = 4.0$. Taking action $a_1$ in $s_1$ yields immediate reward $r = 6.0$ and transitions to $s_2$, where $\max_{a'} Q(s_2, a') = 10.0$. What is the updated $Q(s_1, a_1)$?
**Correct Answer:** A
**Solution:** TD target $= r + \gamma \max_{a'} Q(s_2, a') = 6.0 + 0.8(10.0) = 14.0$.
Updated value: $Q_{\text{new}} = 4.0 + 0.5(14.0 - 4.0) = 4.0 + 5.0 = \mathbf{9.0}$.

### [GATE DA RL | MCQ]
An agent receives a constant reward of $r = +3$ on every step ($t = 0, 1, 2, \dots$) forever in an infinite-horizon MDP with discount factor $\gamma = 0.75$. What is the total discounted return $G_0 = \sum_{k=0}^\infty \gamma^k r$?
**Correct Answer:** C
**Solution:** Infinite geometric series: $G_0 = \frac{r}{1 - \gamma} = \frac{3}{1 - 0.75} = \frac{3}{0.25} = \mathbf{12}$.
