Worked examples — Exploration vs exploitation tradeoff
This page is a worked-example gym. The parent note gave you the tools — regret, epsilon-greedy, UCB, Thompson sampling. Here we swing every tool at every kind of situation, one at a time, so that when an exam or a real project throws you a weird case, you have already seen it.
Before anything, one promise: every symbol used below is either built here or was defined in the parent. Let me re-anchor the ones I lean on most, in plain words.
The scenario matrix
Every problem in this topic is one of these cells. The examples below each carry their cell label so you can see the whole board getting covered.
| Cell | What makes it tricky | Covered by |
|---|---|---|
| C1 Clean two-arm, greedy trap | one unlucky early sample locks you onto the worse arm | Ex 1 |
| C2 Zero-division / never-tried arm | makes UCB's bonus infinite | Ex 2 |
| C3 Tie in estimates | two arms with equal , bonus decides | Ex 3 |
| C4 Limiting behaviour as | does the bonus vanish? does regret stay sublinear? | Ex 4 |
| C5 Epsilon decay arithmetic | picking a schedule, computing explore-probability at a given step | Ex 5 |
| C6 Thompson with Beta, degenerate prior | all-successes or all-failures posterior | Ex 6 |
| C7 Real-world word problem | A/B testing a website button | Ex 7 |
| C8 Exam twist: sparse-reward failure | why -greedy's regret bound quietly breaks | Ex 8 |
Worked Examples
Ex 1 — Cell C1 · the greedy trap
Forecast: guess now — will greedy ever escape? And roughly how many times will 10%-random exploration touch B in 1000 steps?
- Estimates. At this point : , . Why this step? is just the running average of observed rewards up to now; that is the only knowledge the agent has.
- Greedy pick. Greedy always takes . Since , it picks A forever. Why this step? Greedy never pulls B again, so never updates off that one unlucky — the mistake is permanent.
- Greedy per-step regret. Recall is the best possible mean. Regret per step . Over steps (the whole horizon), — linear, unbounded. Why this step? is the reward we could have earned; the gap is what greedy throws away every single step.
- Epsilon-greedy exploration count. With we act randomly of the time; a random pull hits B with prob . Expected B-explorations in : . Why this step? These fresh samples are what let climb toward and overtake — the trap springs open.
Verify: greedy regret at is . Now the rigour on "why 50 is enough": the standard error of an average of Bernoulli samples is . For B with , that is . So after pulls, sits within about of , i.e. above — comfortably past . The gap to beat is , which is more than standard errors, so overtaking is near-certain, not merely "more than one sample." ✓
Ex 2 — Cell C2 · the never-tried arm (zero division)
Forecast: UCB score is (recall is the exploration knob). What happens when you divide by zero?
- Read the bonus for arm 3. divides by zero → the bonus is . Why this step? An arm we know nothing about has unbounded optimism — UCB refuses to skip it.
- The universal convention. Every UCB implementation treats "" as a special case: pull each arm once before applying the formula. Effectively its UCB is . Why this step? Without one sample there is no at all — the formula is undefined, so we bootstrap it.
- So at , arm 3 is chosen. Its infinite bonus beats any finite score from arms 1 and 2. Why this step? This is the guarantee that UCB tries every action at least once — a degenerate input handled by design, not by luck.
- After that pull, say arm 3 returns reward , so ; now recompute with : , which is finite. Why this step? One droplet in the jar turns "infinite curiosity" into an ordinary, comparable score.
Verify: with , arm-1 bonus at is , score — finite. Arm 3's is . UCB picks arm 3. ✓
Ex 3 — Cell C3 · a tie in estimates
Forecast: equal values — does UCB flip a coin, or is there a rule?
- Bonus for arm 1. . Why this step? Big → small bonus. Confident arm, low curiosity.
- Bonus for arm 2. . Why this step? Same , tiny → the denominator shrinks, bonus balloons.
- Scores. UCB; UCB. Why this step? Equal value, unequal certainty. The under-sampled arm wins.
- Interpretation. UCB always breaks a value-tie in favour of the arm it knows less about — "optimism in the face of uncertainty." Why this step? This is exactly the exploration pressure that prevents the greedy trap of Ex 1.
Verify: UCBUCB, so arm 2 chosen. ✓
Read the figure below to see this: each bar is stacked — the violet lower block is the value (identical for both arms), and the orange upper block is the exploration bonus. Arm 2's orange block is much taller because is small, so its total UCB (the top of the stacked bar) overtops Arm 1's despite the identical violet floors. The magenta arrow points to exactly the "extra height from uncertainty" that decides the tie.

Ex 4 — Cell C4 · limiting behaviour as
Forecast: guess whether the bonus goes to , a constant, or infinity.
- Substitute . Bonus . Why this step? We want the growth rate, so express the bonus purely in .
- Take the limit. As , grows but grows far faster, so , hence bonus . Why this step? This is the key promise of UCB: once an arm is heavily sampled, its curiosity dies out and UCB behaves like greedy on that arm.
- Why and not upstairs? If the numerator were the bonus would not vanish; grows just slowly enough that total regret is — sublinear, matching the parent's claim. Why this step? The logarithm is the exact dial that keeps exploring "just enough, forever" without paying linear regret.
- Contrast with fixed- greedy. A constant forces a fixed exploration fraction forever, so its regret stays — linear. Only a decaying (Ex 5) or UCB reaches sublinear. Why this step? This is why "which strategy" matters — the limiting regret order is decided here.
Verify: at , bonus — near zero. ✓
Ex 5 — Cell C5 · epsilon-decay arithmetic
Forecast: guess which schedule is still exploring meaningfully at step 100.
- Exponential at . . Since . Why this step? Multiplying by each step compounds; converting to makes the exponent easy to reason about.
- Harmonic at . . Why this step? Direct substitution; the rule crushes exploration much faster by step 100.
- Compare. Exponential vs harmonic . The exponential schedule still explores of the time — far gentler early decay. Why this step? Gentle decay protects against the greedy trap when early estimates are noisy; aggressive decay commits faster.
- Rule of thumb. Hard exploration problems → gentle (exponential or slow) decay; easy problems with clean signal → fast decay is fine. Why this step? The schedule is a knob trading early caution against late efficiency — the tradeoff, again, one level down.
Verify: and , and . ✓
Ex 6 — Cell C6 · Thompson sampling, degenerate posterior
Forecast: arm X looks perfect (4/4). Does Thompson ever explore Y again?
- Posteriors. The update rule is , where = successes and = failures. Arm X: . Arm Y: . Why this step? Each success shifts the first parameter up, each failure shifts the second parameter up; the posterior is our belief over .
- Posterior means. ; . Why this step? The mean is our point-guess; X currently looks much better.
- Widths (variance). Beta variance . For X: . For Y: . Y is wider (more uncertain). Why this step? Fewer effective samples on Y → broader belief.
- Why Y still gets picked sometimes. Thompson samples and each round and takes the larger. Y's wide posterior occasionally draws a high — that's the exploration, and it self-throttles as Y gathers data. Why this step? No hand-set or bonus — exploration falls straight out of the uncertainty. That is the elegance of probability matching.
Verify: means and ; variances and , and , so Y is wider. ✓
Read the figure below to see the exploration: the magenta curve is Arm X's posterior — tall, narrow, and shoved up against (confident it's good). The orange curve is Arm Y's — lower and much wider, its right tail stretching well past . Because Thompson draws a random point under each curve and picks the arm with the larger draw, Y's fat right tail means it will occasionally out-sample X's peak — that overlap region (violet arrow) is precisely where Y gets re-explored.

Ex 7 — Cell C7 · real-world word problem (A/B test)
Forecast: magenta has the higher raw rate. Does UCB agree, or does equal sample size change the story?
- Estimates. ; . Why this step? Conversion rate is a reward mean — exactly the bandit setting, here purchase probability.
- Bonuses. Both have , so both get the same bonus . Why this step? Equal sample sizes → equal uncertainty → the bonus cancels out in the comparison.
- UCB scores. Magenta ; orange . Why this step? With equal bonus, UCB reduces to greedy — the higher estimate wins.
- Decision & caution. Show magenta. But note the gap is small vs the bonus ; the data is not yet conclusive, so UCB keeps testing both until one pulls clearly ahead — this is exactly guarding against over-fitting to a noisy early lead. Why this step? A real A/B test should not "call it" on a 30-vs-24 difference; the bonus encodes that statistical humility.
Verify: , magenta chosen; both bonuses equal so they cancel and greedy order holds. ✓
Ex 8 — Cell C8 · exam twist, why the bound quietly breaks
Forecast: guess the odds — is uniform random exploration realistically ever going to find this?
- Single-rollout success probability. Each step independently correct with prob ; twenty steps: . Why this step? Independent choices multiply; sparse rewards make the "target" a needle in a haystack.
- Expected rollouts to first success. For a geometric event with per-trial success probability , the mean number of trials until the first success is . Here . Why this step? This is astronomically more than any real training budget (a fast simulator doing rollouts a second would still need over million years) — success essentially never happens.
- Why the bound fails. That regret bound (with the total horizon) assumed a finite set of arms, each sampled directly and each with its own independently-estimable mean . Here the "good arm" is a deep 20-step sequence, not a single pull-able action; uniform exploration almost never lands on it, so the estimates for the rewarding path never even begin to form. The bandit assumptions (each action independently learnable in pulls) are violated, so the theorem simply does not cover this environment. Why this step? The exam trap is applying a clean theorem outside its hypotheses — always check that the assumptions actually hold.
- The fix. Replace uniform exploration with a directed signal — an intrinsic novelty bonus , where is the environment's (sparse) reward, is large for unfamiliar states, and weights curiosity against real reward. This is curiosity-driven exploration: the agent is pulled toward unseen states rather than stumbling randomly. Why this step? When random exploration's success probability is , you must change what counts as interesting, not just how often you explore.
Verify: and ; and seconds years, confirming "essentially never." ✓
Recall Self-test before you leave
Greedy's regret grows how, and why? ::: Linearly ( in Ex 1), because one unlucky sample locks it onto the worse arm and it never re-samples. When , what is UCB's bonus and what do we do? ::: ; pull every arm once first so is defined (Ex 2). Two arms tie on — who does UCB pick? ::: The one with smaller , i.e. the less-sampled, more-uncertain arm (Ex 3). Why is (not ) in the UCB bonus? ::: So the bonus as samples grow, giving sublinear regret instead of linear (Ex 4). What does the knob control in UCB? ::: How brave exploration is — bigger scales up the whole bonus term, smaller makes UCB act more greedily. Why does Thompson explore without any ? ::: A wide posterior occasionally samples a high value, and it self-narrows as data arrives (Ex 6). Why does -greedy fail on Montezuma-style tasks? ::: Reward needs a deep sequence; uniform exploration hits it with prob , breaking the bandit assumptions (Ex 8).
Where to go next: the estimate used everywhere here is exactly what Q-learning learns online, built on temporal-difference updates; the bandit setup is formalised in multi-armed bandits; and when exploration must be directed by a learned objective, see policy-gradient methods.