~/problems / Probability / Probability and expected value

Restart strategies for a random solve time

hard 3 levels ~60 min OpenAI

Level 1 Guarantees when you only know the mean

A model solves a request in a random time T >= 0. All you know is E[T] = mean. You may restart: give up on an attempt when it hits its timeout and start a fresh, independent attempt. The request succeeds if some attempt finishes within its timeout (an attempt with timeout t succeeds iff its T <= t). Restarting costs nothing.

Return exact fractions.Fraction values. Inputs are ints or Fractions.

  1. markov_tail_bound(mean, a): the best upper bound on P(T > a) that holds for every nonnegative T with that mean: min(1, mean / a), or 1 when a <= 0.
  2. worst_case_example(mean, a, eps): show the bound is essentially tight. Return a distribution as a dict {value: probability} with exactly two values, 0 and a + eps, with mean exactly mean and P(T > a) = mean / (a + eps). You may assume 0 < mean <= a and eps > 0.
  3. restart_guarantee(mean, timeouts): the success probability guaranteed by applying the Markov bound to each independent attempt, when you run one attempt per timeout in timeouts. (For unequal timeouts no single distribution need hit every bound at once, so this is a valid lower bound on the true worst case rather than exactly equal to it.)
  4. best_equal_split(mean, budget): split a total time budget into m >= 1 equal timeouts budget / m. Return (m, guarantee) for the m with the largest guarantee, taking the smallest m on ties. When nothing positive can be guaranteed, return (1, 0).
markov_tail_bound(1, 5)            # 1/5
restart_guarantee(1, [5, 5])       # 24/25
best_equal_split(1, 10)            # (4, 609/625): four tries of 2.5 minutes beat two of 5

Be ready to explain roughly where the best m lies as a function of budget / mean, and why unequal timeouts can't raise this guarantee.

Show hint

For the explanation: maximise (budget / (m · mean))^m over real m, and compare a product of per-attempt bounds with fixed sum of timeouts using AM-GM.

Level 2 unlocks when level 1 passes.

Level 3 unlocks when level 2 passes.

Topic: Probability and expected value. Linearity of expectation, conditioning, Markov-chain equations; answers as fractions.

0:00
Ctrl ' run · Ctrl ↵ submit
esc