Ski Rental: The Rent-or-Buy Decision
Ski Rental: The Rent-or-Buy Decision
Here is a decision you have made a hundred times without noticing it was the same decision every time. Do you keep paying small amounts as you go, or do you make one big commitment up front and be done with it? Rent the apartment or buy the house. Pay per API call or reserve capacity. Keep reconnecting or hold the connection open. Each little payment feels harmless, but they add up, and the commitment only pays off if you end up using the thing long enough. The catch, always, is that you do not know how long that will be. Ski rental is this decision stripped to its bones, and it is the perfect first problem in competitive analysis because you can hold the entire thing in your head and still be surprised by how tight the answer is.
The setup: you are going skiing for some number of days you do not know in advance. Renting skis costs $1 per day. Buying them costs $B, once, after which skiing is free. Every morning you show up and must decide, rent again or buy now, and the season ends whenever it ends, without warning.
The offline optimum needs a crystal ball
Suppose for a moment you did know the total number of days D. Then the decision is trivial. If you will ski fewer than B days, rent the whole time and pay $D. If you will ski B days or more, buy on the very first morning and pay $B. So the offline optimum is
OPT=min(D,B).
That min is doing something you are not allowed to do: it peeks at D. OPT is the omniscient benchmark, the best any strategy could possibly achieve with the whole season revealed in advance. Your job is to stay close to it while blind.
The break-even rule: rent until renting has cost you a purchase
The online strategy is beautifully simple: keep renting until your total spent on rentals equals the purchase price, and then buy. Concretely, rent for the first B - 1 days, and if you are still skiing on day B, buy. You spend a dollar a day right up until the moment your accumulated rent would have bought the skis outright, and only then do you commit.
Walk it through with B = 10, so buying costs $10, the same as ten days of rental.
| how long the season turns out to be | what you pay | OPT | ratio |
|---|---|---|---|
| 4 days | rent 4 = $4 | $4 | 1.0 |
| 9 days | rent 9 = $9 | $9 | 1.0 |
| 10 days | rent 9, then buy = $19 | $10 | 1.9 |
| 30 days | rent 9, buy, ski free = $19 | $10 | 1.9 |
If the season is short, you rented the whole time and matched OPT exactly. The only place you overpay is when the season runs long enough that buying was the right call all along: you rented B - 1 days for $9 and then paid $10 to buy, a total of $19, while the clairvoyant OPT bought on day one for $10. That worst case is 2B - 1 against OPT's B, a ratio of
B2B−1=2−B1.
So the break-even rule is (2 - 1/B)-competitive: never worse than a hair under twice the optimum, no matter how the season plays out. For large B that hair vanishes and the ratio is essentially 2. You paid at most double for the privilege of not knowing the future.
Why you cannot do better: the adversary
A ratio close to 2 might feel like something a cleverer rule could beat. It cannot, and the way we know is the move that recurs through this entire subject: imagine an adversary who knows your strategy exactly and chooses the season length to hurt you as much as possible.
Any deterministic strategy is really just a decision about which day to buy, call it day j: you rent days 1 through j - 1, then buy on day j. The adversary, seeing your j, simply ends the season on day j, the moment your purchase becomes wasted. You have now paid (j - 1) in rent plus $B to buy, while OPT pays min(j, B). If you buy too early (small j), the season that stops right there means you bought skis you barely used. If you buy too late (large j), you have burned a fortune in rent. Balancing those two regrets lands exactly on j = B, and the resulting ratio is the same 2 - 1/B we already found. No deterministic online algorithm for ski rental beats it. The break-even rule is not merely good, it is provably the best possible, and 2 - 1/B is a matching lower bound.
Flipping coins to beat the bound
The lower bound of 2 - 1/B has a loophole worth its own paragraph, because it is where online algorithms get genuinely surprising. It applies only to deterministic strategies, ones whose buy-day the adversary can figure out in advance. If instead you randomize the day you buy, drawing it from a carefully chosen distribution, the adversary can no longer aim precisely at your decision, because you yourself do not know it until the coin lands. Against an oblivious adversary, one who must fix the season length without seeing your coin flips, a randomized ski-rental strategy achieves an expected competitive ratio of
e−1e≈1.58,
comfortably below the deterministic wall of 2. And that too is tight: no randomized strategy does better. A little unpredictability, spent well, buys back a real chunk of the price of ignorance. This tension, between what a deterministic algorithm must concede and what randomization can reclaim, is one of the most beautiful recurring themes ahead.
In the wild
Ski rental is a toy, but the rent-or-buy shape it captures is everywhere a system weighs pay-as-you-go against a one-time commitment under an unknown horizon. Cloud capacity is the cleanest echo: on-demand instances are the daily rental, a reserved instance is the purchase, and you rarely know upfront how long a workload will run, so "commit once your on-demand spend would have paid for the reservation" is the break-even rule wearing a billing dashboard. The same logic governs whether to keep a network connection alive or tear it down and reconnect later, whether to spin up a dedicated resource or keep paying per use, and whether to cache and precompute or recompute on demand. Whenever you catch yourself asking "is this going to last long enough to justify committing," you are standing in the ski rental problem, and the break-even rule is a genuinely good answer.
The takeaway
Ski rental is the atom of online decision-making: a single irrevocable commitment, an unknown future, and a clean way to measure the damage. The break-even rule guarantees you never pay more than about twice what perfect foresight would have, that factor of 2 is exactly the price of not knowing the horizon, and randomization shaves it down toward 1.58. Best of all, matching lower bounds prove both numbers are the honest truth rather than the limit of our cleverness. Keep the shape in mind: much of what follows is other problems whose "buy" and "rent" are disguised, and whose competitive ratios are found the same way, by pitting a simple online rule against an adversary who has read your playbook.
Ski Rental: The Rent-or-Buy Decision
The ski rental problem, the archetype of online rent-or-buy decisions. The break-even rule is (2 - 1/B)-competitive and provably optimal for deterministic algorithms, while randomization brings the ratio down to e/(e-1), a hands-on first tour of competitive ratios and adversary lower bounds.