Home▸Articles▸AI & Machine Learning

Cliff Walking: SARSA vs Q-Learning

Explore how two reinforcement learning algorithms navigate a treacherous cliff edge in this classic gridworld problem.

mysimulator teamUpdated June 2026≈ 3 min read▶ Open the simulation

What is Reinforcement Learning?

Reinforcement learning (RL) is a type of machine learning where an agent learns to make decisions by performing actions in an environment and receiving rewards or penalties. The goal is for the agent to learn a policy that maximizes its long-term reward.

In the context of the Cliff Walking problem, the agent must navigate from the start state to the goal state while avoiding the cliff edge, which results in a significant penalty.

Understanding SARSA and Q-Learning

SARSA (State-Action-Reward-State-Action) is an on-policy algorithm that updates its value function based on the current state-action pair. It follows the policy it is learning, meaning it explores actions according to the learned probabilities.

Q-learning, in contrast, is off-policy and learns a value function for every possible action-state combination without following any specific policy during training. This allows Q-learning to explore more aggressively, potentially leading to different strategies.

live demo · related simulation● LIVE

The Cliff Walking Problem

In the Cliff Walking problem, an agent moves through a grid where it can move up, down, left, or right. The goal is to reach the bottom-right corner without falling off the cliff edge, which incurs a large penalty.

This problem highlights how different learning algorithms handle exploration and exploitation, leading to distinct strategies for navigating the environment.

Comparison of SARSA vs Q-Learning

SARSA tends to be more cautious in its approach, often opting for safer paths that avoid high-risk areas like the cliff edge. This is because it updates its value function based on the actions it actually takes, leading to a more conservative policy.

Q-learning, however, can explore riskier options and find shorter but potentially dangerous routes due to its off-policy nature, which allows it to consider all possible actions regardless of the current policy.

Frequently asked questions

What is the difference between on-policy and off-policy learning?

On-policy methods like SARSA learn based on the policy they are following, meaning they explore actions according to the same strategy they use for decision-making. Off-policy methods like Q-learning can learn from any behavior, regardless of whether it follows a specific policy.

Why does Q-Learning find riskier paths in the Cliff Walking problem?

Q-Learning explores all possible actions and updates its value function based on the best action for each state. This allows it to discover shorter but potentially dangerous routes, while SARSA tends to follow safer paths more consistently.

Can both algorithms be tuned to avoid risks?

Yes, by adjusting parameters like the exploration rate (epsilon) and learning rate (alpha), both SARSA and Q-Learning can be made to explore less aggressively, potentially leading them to safer paths in the Cliff Walking problem.

What are some real-world applications of reinforcement learning?

Reinforcement learning is used in various fields such as robotics for autonomous navigation, game playing (e.g., AlphaGo), and even in financial trading algorithms where agents learn to make optimal decisions based on market data.

Try it live

Everything above runs in your browser — open Cliff Walking: SARSA vs Q-Learning and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.

▶ Open Cliff Walking: SARSA vs Q-Learning simulation

What did you find?

Add reproduction steps (optional)