Everything2
Near Matches
Ignore Exact
Full Text
Everything2

Ski rental problem solution

created by haggai

(idea) by haggai (7.4 mon) (print)   ?   (I like it!) Sat Feb 22 2003 at 14:40:06

This is the optimal c-competitive solution to the Ski Rental Problem, with some explanation. Yup, it's a spoiler, but there are plenty of other online algorithm problems you can have a go at.

SPOILER ALERT

First off, what would the "omniscient" offline algorithm do? Obviously, it knows the total number of days you'll be skiing, and that's all that matters. If you'll be skiing 15 days or more, you should buy the skis (since renting will cost more than 15 x $10). If less, renting is your best choice.

But our online algorithm won't know the total number of days ahead of time. On the other hand, the input is rather limited: at day i, so long as you haven't bought the skis, the input is simply "it's day i, and we're still skiing". Once you buy the skis, there are no more decisions to make. So an online algorithm is really just a number N: if and when you reach day N, the algorithm says you should buy those skis. The input, in this reformulation, is simply D, the number of days you end up skiing.

So what N is best? If N is very low, you risk paying N x $10 + $150, when for a potentially short holiday you could have kept renting (and paid, say (N+1) x $10). If N is very high, you risk paying the cost of buying the skis many times over.

Unsurprisingly, perhaps, the answer is a half-way compromise: rent until day 15, then buy. This algorithm is 2-competitive. You never pay more than $300, so any other (offline) solution which involves buying the skis can be no more than twice as good. If the holiday ends any time up to day 15, renting is obviously optimal, and if it ends after day 15, even the optimal solution must involve paying at least $150. Thus, any "omniscient" algorithm can fare no better than paying half what our online algorithm does.

Is 2 optimal? Yes! Simply go through the considerations of the previous paragraph with N less than 15, and again with N greater than 15, and note that some value of D always makes you pay more than twice what you could have managed (with hindsight). "Balance" is often a good approach to online algorithms; it is often c-competitive for some intuitive c, and occasionally (as in this case) optimal.

Happy skiing!


printable version
chaos

Ski rental problem online algorithm Ski trail difficulty classifications offline algorithm
compromise optimal Copper Mountain Automag
competitive analysis omniscient spoiler Après Ski
after ski Getting off a ski lift on a snowboard water ski conditioning ski bunny
E2 Link and Logger Client balance input
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
The best nodes of all time:
Bullfighting
In Los Angeles, something is always burning
Brian Eno
Walter Matthau
Ocean's Twelve
Lawrence Textile Strike
Agent Orange
She breaks hearts almost as often as she breaks the speed of sound
Hinduism
Moai
Music isn't free
hush puppies
He who has enough to eat does the hungry not believe
New Writeups
jessicaj
July 26, 2008(dream)
Berek
ABBA(person)
devolution
k-hole(place)
Nadine_2
The Sound Of Madness(review)
Twin Eclipse
Conversations with God: An Uncommon Dialogue(idea)
SwimmingMonkey
Conversations with Fo Fo- the Loneliest dog in Purgatory(fiction)
locke baron
lynx(thing)
Simulacron3
Reality, Dimensions and the Natural Ontology(essay)
SubSane
Making Love to a 9-Foot Woman(person)
Ouzo
Thoughts(idea)
antigravpussy
I fall silent, listening. The breadcrumbs are talking about us(person)
calgon
Buffalo Bill by the pool(poetry)
gate
Anarchy is Order(idea)
ushdfgakjasgh
Scribeling(thing)
XWiz
Trism(review)
E2 is a by-product of the existence of The Everything Development Company