0% found this document useful (0 votes)
46 views17 pages

Competitive Analysis: Steven Skiena

This document discusses competitive analysis, which evaluates online algorithms that must make predictions without complete knowledge of future inputs. It provides examples of online problems in computer science and finance. The key aspects covered are: - Competitive analysis compares an online algorithm's performance on a problem to an optimal offline algorithm that knows the future inputs. - The competitive ratio measures how much worse an online algorithm can be than optimal, usually expressed as a constant factor c. - Randomized algorithms can help online algorithms against an adversary by introducing randomness the adversary cannot predict.

Uploaded by

Aman Machra
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views17 pages

Competitive Analysis: Steven Skiena

This document discusses competitive analysis, which evaluates online algorithms that must make predictions without complete knowledge of future inputs. It provides examples of online problems in computer science and finance. The key aspects covered are: - Competitive analysis compares an online algorithm's performance on a problem to an optimal offline algorithm that knows the future inputs. - The competitive ratio measures how much worse an online algorithm can be than optimal, usually expressed as a constant factor c. - Randomized algorithms can help online algorithms against an adversary by introducing randomness the adversary cannot predict.

Uploaded by

Aman Machra
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Lecture 21: Competitive Analysis Steven Skiena Department of Computer Science State University of New York Stony Brook,

NY 117944400 http://www.cs.sunysb.edu/skiena

Motivation: Online Problems


Many problems in both nance and computer science reduce to trying to predict the future. . . Examples from computer science include cache and virtual memory management. Examples from nance typically revolve around predicting future returns for an asset, or designing a portfolio to maximize future returns. Such problems become trivial if we know the future (i.e. the stream of future memory requests or tomorrows newspaper), but typically we only have access to the past.

On Line vs. Off Line


An off-line problem provides access to all the relevant information to compute a result. An online problem continually produces new input and requires answers in response.

Competitive Analysis
How can we theoretically evaluate how well an algorithm forecasts the future? Statistical forecasts provide a predict the future that makes some sense in practice. However, they offer no future guarantees, particularly if the data distribution changes. Competitive analysis offers a worst-case measure of the quality of the behavior of an algorithm which predicts the future. We seek to compare the performance of algorithm A with only knowledge of the past with an algorithm which has complete knowledge of past and future makes optimal use of it.

Competitive Ratio
We say an online algorithm ALG is c-competitive if there is a constant such that for all nite input sequences I , ALG(I ) c OP T (I ) + Note that the additive constant is a xed cost that becomes unimportant as the size of the problem increases. We do not particularly care about the run-time efciency of ALG (except maybe that it is polynomial), but we do care about its competitive ratio c.

The Ski Rental Problem


Consider the problem of deciding when to purchase skis. Whenever you go skiing, you can either rent skis for the day at cost x, or buy them for b x. If you buy them the rst day, the worst case is you never ski again, and you spent b times the optimal decision of simply renting. Suppose you never buy them. After k > b days, you have spent k/b times the optimal decision of buying from the rst day.

When to Stop Renting. . .


But suppose you buy them after renting b times. You did the right thing if you go k < b times. If you go exactly b times, you spent twice as much as the optimal decision, but never changes after that. Thus this balancing algorithm is 2-competitive. We can view any online algorithm as a game between an online player (the skier) and a malicious adversary (his/her anterior cruciate ligament).

Searching for a Price


Suppose that we want to sell a indivisible asset (say a house) sometime over the next n days. Say the price uctuates on a daily basis in the real interval [m, M ], where m is the lowest possible price and M is the highest possible price. What strategy can we use to sell the asset and get the highest possible price?

Buy Low, Sell High


If we knew the future history, the optimal strategy would be to sell at the maximum price occurring over the n days. We seek a strategy which optimizes competitive ratio, i.e. which minimizes the maximum ratio of the price we get over the maximum price. We do not seek a price which is good related to the average, but good in the worst case. What can we do?

Deterministic Price Searching


Note that if the price was high at one point but we didnt sell, our adversary could immediately and permanently lower the price to m. Note that once we sell, our adversary can immediately raise the price to M . At the end of the time period, we can always get a price of at least m. Together, this suggests that we should sell the instant the price reaches some p which is high enough that we do OK in each instance. The worst we do in the rst case is p/m. The worst we do in the second case is M/p. Balancing them yields:

p M = p = Mm m p The reservation price policy (RPP) accepts the rst price greater than or equal to p = M m. Let = M/m dene the global uctuation ratio. The competitive ratio c we get is M c = M m/m = = m This is the optimal deterministic strategy.

Randomized Algorithms
Randomized algorithms use random numbers to design algorithms unlikely to encounter the worst possible case. Randomization is particularly useful to make things difcult for an adversary to design a future that is bad for you. We assume he has access to your program but not to read or effect the random numbers. In an analysis of a randomized algorithms, we determine the expected value over all random number sequences for the worst possible input. Thus our analysis is completely independent of the input distribution randomized expectation has nothing to do with statistical expectation.

Example: Finding a Tire Leak


Suppose I ride over a tack and get a at tire. What is the best way I can nd the location of the tack, assuming I can only explore 1/nth of the wheel at a time? If I use the deterministic strategy of repeatedly turning the wheel left 2/n radians until I nd the tack, my adversary can put the tack just right of the initial position. This strategy yields a cost of n versus the optimal off-line cost of 1, for a competitive ratio of n. Suppose instead I spin the wheel around randomly and then start walking to the left. Regardless of where the adversary puts the tack, my expected search cost (and competitive ratio) is n/2.

Randomized Price Searching


Suppose that = M/m = 2k for some integer k , i.e. M = m2k . Let RP Pi be the deterministic reservation price policy where we sell as soon at the price hits m2i. The strategy EXP O picks an integer i uniformly at random from 1, . . . , k , and then sells as the price hits m2i. There must be some j such that the optimum off-line return pmax lies between m2j pmax < m2j +1 . What can the adversary do? Knowing we are restricted to picking values of the form m2i, they will pick a value of the form m2j +1 to frustrate us for some j .

Analysis Idea
Suppose the adversary picks j . Our target i was too big with probability (k j )/k if so we were forced to settle for a price of m. Our target i was less than pmax otherwise, meaning were able to realize our price.

Analysis
Our expected price is: kj 1 j EXP O(j ) = m+ m2i k k i=i j m k j + = 2i i=i k m = k j + 2j +1 2 k The competitive ratio is OP T m2j +1 c = =m EXP O(j ) (k j + 2j +1 2) k 2j +1 k O (k ) j +1 kj+2 2 (1) (2) (3)

(4) (5)

The competitive ratio is maximized when k is largest, for a competitive ratio of O (log ). Note that the ner gradations in price level are at the low end of the range, not the high end where they mean more in absolute dollars.

You might also like