On-Line Difference Maximization.
In this paper we examine problems motivated by on-line financial problems and stochastic games.  In particular, we consider a sequence of entirely arbitrary distinct values arriving in random order, and must devise strategies for selecting low values followed by high values in such a way as to maximize the expected gain in rank from low values to high values.First, we consider a scenario in which only one low value and one high value may be selected.  We give an optimal on-line algorithm for this scenario, and analyze it to show that, surprisingly, the expected gain is n-O(1), and so differs from the best possible off-line gain by only a constant additive term (which is, in fact, fairly small---at most 15).In a second scenario, we allow multiple nonoverlapping low/high selections, where the total gain for our algorithm is the sum of the individual pair gains.  We also give an optimal on-line algorithm for this problem, where the expected gain is $n^2/8-\Theta(n\log n)$.  An analysis shows that the optimal expected off-line gain is $n^2/6+\Theta(1)$, so the performance of our on-line algorithm is within a factor of 3/4 of the best off-line strategy.
Introduction
. In this paper, we examine the problem of accepting values
from an on-line source and selecting values in such a way as to maximize the difference
in the ranks of the selected values. The input values can be arbitrary distinct real
numbers, and thus we cannot determine with certainty the actual ranks of any input
values until we see all of them. Since we only care about their ranks, an equivalent way
of defining the input is as a sequence of n integers x
denotes the rank of the ith input item among the first i
items. These ranks uniquely define an ordering of all n inputs, which can be specified
with a sequence of ranks r these ranks form a permutation of the
set ng. We refer to the r i ranks as final ranks, since they represent the rank
of each item among the final set of n inputs. We assume that the inputs come from
a probabilistic source such that all permutations of n final ranks are equally likely.
The original motivation for this problem came from considering on-line financial
problems [2, 4, 7, 8, 9], where maximizing the difference between selected items naturally
corresponds to maximizing the difference between the buying and selling prices
of an investment. While we use generic terminology in order to generalize the setting
(for example, we make a "low selection" rather than pick a "buying price"), many of
the problems examined in this paper are easily understood using notions from invest-
ing. This paper is a first step in applying on-line algorithmic techniques to realistic
on-line investment problems.
While the original motivation comes from financial problems, the current input
model has little to do with realistic financial markets, and is selected for its mathe-
Received by the editors July 29, 1996; accepted for publication (in revised form) March 5, 1998;
published electronically DATE.
y Department of Computer Science, Yale University, New Haven, CT 06520
(kao-ming-yang@cs.yale.edu). Supported in part by NSF Grant CCR-9531028.
z Department of Computer Science, University of North Texas, Denton,
(srt@cs.unt.edu). Supported in part by NSF Grant CCR-9409945.
M. Y. KAO AND S. R. TATE
matical cleanness and its relation to fundamental problems in stochastic games. The
main difference between our model and more realistic financial problems is that in
usual stock trading, optimizating rank-related quantities is not always correlated to
optimizing profits in the dollar amount. However, there are some strong similarities
as well, such as exotic financial derivatives based on quantities similar to ranks [20].
The current formulation is closely related to an important mathematical problem
known as the secretary problem [11, 6], which has become a standard textbook
example [3, 5, 19], and has been the basis for many interesting extensions (includ-
ing [1, 14, 15, 17, 18]). The secretary problem comes from the following scenario:
A set of candidates for a single secretarial position are presented in random order.
The interviewer sees the candidates one at a time, and must make a decision to hire
or not to hire immediately upon seeing each candidate. Once a candidate is passed
over, the interviewer may not go back and hire that candidate. The general goal is to
maximize either the probability of selecting the top candidate, or the expected rank of
the selected candidate. This problem has also been stated with the slightly different
story of a princess selecting a suitor [3, p. 110]. More will be made of the relationship
between our current problem and the secretary problem in x2, and for further reading
on the secretary problem, we refer the reader to the survey by Freeman [10].
As mentioned above, we assume that the input comes from a random source in
which all permutations of final ranks are equally likely. Thus, each rank
x i is uniformly distributed over the set f1; all ranks are independent of
one another. In fact, this closely parallels the most popular algorithm for generating
a random permutation [13, p. 139]. A natural question to ask is, knowing the relative
rank x i of the current input, what is the expected final rank of this item (i.e., E[r i jx i ])?
Due to the uniform nature of the input source, the final rank of the ith item simply
scales up with the number of items left in the input sequence, and so E[r i jx
(a simple proof of this is given in Appendix A).
Since all input ranks x i are independent and uniformly distributed, little can
be inferred about the future inputs. We consider games in which a player watches
the stream of inputs, and can select items as they are seen; however, if an item is
passed up then it is gone for good and may not be selected later. We are interested
in strategies for two such games:
ffl Single pair selection: In this game, the player should make two selections, the
first being the low selection and the second being the high selection. The goal
of the player is to maximize the difference between the final ranks of these
two selections. If the player picks the low selection upon seeing input x ' at
time step ', and picks the high selection as input x h at time step h, then the
profit given to the player at the end of the game is the difference in final ranks
of these items: r
ffl Multiple pair selection: In this game, the player makes multiple choices of
low/high pairs. At the end of the game the difference in final ranks of each
selected pair of items is taken, and the differences for all pairs are added up
to produce the player's final profit.
The strategies for these games share a common difficulty: If the player waits too long
to make the low selection, he risks not having enough choices for a good high selection;
however, making the low selection too early may result in an item selected before any
truly low items have been seen. The player in the second game can afford to be less
selective. If one chosen pair does not give a large difference, there may still be many
other pairs that are good enough to make up for this pair's small difference.
ON-LINE DIFFERENCE MAXIMIZATION 3
We present optimal solutions to both of the games. For the first game, where
the player makes a single low selection and a single high selection, our strategy has
expected profit From the derivation of our strategy, it will be clear that the
strategy is optimal. Even with full knowledge of the final ranks of all input items, the
best expected profit in this game is less than n, and so in standard terms of on-line
performance measurement [12, 16], the competitive ratio 1 of our strategy is one. The
strength of our on-line strategy is rather intriguing.
For the second game, where multiple low/high pairs are selected, we provide an
optimal strategy with expected profit 1
log n). For this problem, the optimal
off-line strategy has expected profit of approximately 1
so the competitive
ratio of our strategy is 4
3 .
2. Single Low/High Selection. This section considers a scenario in which the
player may pick a single item as the low selection, and a single later item as the high
selection. If the low selection is made at time step ' and the high selection is made
at time step h, then the expected profit is E[r The player's goal is to use a
strategy for picking ' and h in order to maximize this expected profit.
As mentioned in the previous section, this problem is closely related to the secretary
problem. A great deal of work has been done on the secretary problem and
its variations, and this problem has taken a fundamental role in the study of games
against a stochastic opponent. Our work extends the secretary problem, and gives
complete solutions to two natural variants that have not previously appeared in the
literature.
Much insight can be gained by looking at the optimal solution to the secretary
problem, so we first sketch that solution below (using terminology from our problem
about a "high selection"). To maximize the expected rank of a single high selection,
we define the optimal strategy recursively using the following two functions:
Hn (i): This is a limit such that the player selects the current item if
Rn (i): This is the expected final rank of the high selection if the optimal
strategy is followed starting at the ith time step.
Since all permutations of the final ranks are equally likely, if the ith input item
has rank x i among the first i data items, then its expected final rank is n+1
an optimal strategy for the secretary problem is to select the ith input item if and
only if its expected final rank is better than could be obtained by passing over this
item and using the optimal strategy from step In other words, select the
item at time step i ! n if and only if
If we have not made a selection before the nth step, then we must select the last item,
whose rank is uniformly distributed over the range of integers from 1 to n - and so
the expected final rank in that case is Rn
2 . For
"Competitive ratio" usually refers to the worst-case ratio of on-line to off-line cost; however,
in our case inputs are entirely probabilistic, so our "competitive ratio" refers to expected on-line to
expected off-line cost - a worst-case measure doesn't even make sense here.
4 M. Y. KAO AND S. R. TATE
and to force selection at the last time step define Hn Furthermore, given this
definition for Hn (i), the optimal strategy at step i depends only on the rank of the
current item (which is uniformly distributed over the range and the optimal
strategy at time i+1. This allows us to recursively define Rn (i) as follows when
2 , we have a full recursive specification of both the
optimal strategy and the performance of the optimal strategy. The performance of
the optimal strategy, taken from the beginning, is Rn (1). This value can be computed
by the recursive equations, and was proved by Chow et al. to tend to n
Furthermore, the performance approaches this limit from
above, so for all n we have performance greater than
For single pair selection, once a low selection is made we want to maximize the
expected final rank of the high selection. If we made the low selection at step i,
then we can optimally make the high selection by following the above strategy for the
secretary problem, which results in an expected high selection rank of Rn (i 1). How
do we make the low selection? We can do this optimally by extending the recursive
definitions given above with two new functions:
Ln (i): This is a limit such that the player selects the current item if
Pn (i): This is the expected high-low difference if the optimal strategy for
making the low and high selections is followed starting at step i.
Thus, if we choose the ith input as the low selection, the expected profit is Rn (i+
We should select this item if that expected profit is no less than the
expected profit if we skip this item. This leads to the definition of Ln (i):
Using Ln (i), we derive the following profit function:
From the derivation, it is clear that this is the optimal strategy, and can be implemented
by using the recursive formulas to compute the Ln (i) values. The expected
profit of our algorithm is given by Pn (1), which is bounded in the following theorem.
Theorem 2.1. Our on-line algorithm for single low/high selection is optimal and
has expected profit
Proof. It suffices to prove that a certain inferior algorithm has expected profit
O(1). The inferior algorithm is as follows: Use the solution to the secretary problem
ON-LINE DIFFERENCE MAXIMIZATION 5
to select, from the first bn=2c input items, an item with the minimum expected final
rank. Similarly, pick an item with maximum expected rank from the second dn=2e
inputs. For simplicity, we initially assume that n is even; see comments at the end of
the proof for odd n. Let ' be the time step in which the low selection is made, and
h the time step in which the high selection is made. Using the bounds from Chow et
al. [6], we can bound the expected profit of this inferior algorithm by
Chow et al. [6] show that c - 3:87, and so the expected profit of the inferior algorithm
is at least n \Gamma 14:48. For odd n, the derivation is almost identical, with only a change
in the least significant term; specifically, the expected profit of the inferior algorithm
for odd n is
n+3 , which again is at least n \Gamma 14:48.
3. Multiple Low/High Selection. This section considers a scenario in which
the player again selects a low item followed by a high item, but may repeat this
process as often as desired. If the player makes k low and high selections at time
steps respectively, then we require that
The expected profit resulting from these selections is
3.1. Off-line Analysis. Let interval j refer to the time period between the
instant of input item j arriving and the instant of input item arriving. For a
particular sequence of low and high selections, we call interval j active if '
for some index i. We then amortize the total profit of a particular algorithm B by
defining the amortized profit AB (j) for interval j to be
ae r
Note that for a fixed sequence of low/high selections, the sum of all amortized profits
is exactly the total profit, i.e.,
For an off-line algorithm to maximize the total profit we need to maximize the
amortized profit, which is done for a particular sequence of r i 's by making interval
active if and only if r j+1 ? r j . Translating this back to the original problem of
making low and high selections, this is equivalent to identifying all maximal-length
increasing intervals and selecting the beginning and ending points of these intervals
as low and high selections, respectively. These observations and some analysis give
the following lemma.
6 M. Y. KAO AND S. R. TATE
Lemma 3.1. The optimal off-line algorithm just described has expected profit6
Proof. This analysis is performed by examining the expected amortized profits
for individual intervals. In particular, for any interval j,
Since there are and the above analysis is independent of the interval
number j, summing the amortized profit over all intervals gives the expected profit
stated in the lemma.
3.2. On-line Analysis. In our on-line algorithm for multiple pair selection,
there are two possible states: free and holding. In the free state, we choose the
current item as a low selection if x furthermore, if we select an item then we
move from the free state into the holding state. On the other hand, in the holding
state if the current item has x i ? i+1
, then we choose this item as a high selection
and move into the free state. We name this algorithm OP, which can stand for
"opportunistic" since this algorithm makes a low selection whenever the probability
is greater than 1
2 that the next input item will be greater than this one. Later we will
see that the name OP could just as well stand for "optimal," since this algorithm is
indeed optimal.
The following lemma gives the expected profit of this algorithm. In the proof of
this lemma we use the following equality:
Lemma 3.2. The expected profit from our on-line algorithm is
if n is even,
if n is odd.
In cleaner forms we have E[POP
Proof. Let R i be the random variable of the final rank of the ith input item. Let
AOP (i) be the amortized cost for interval i as defined in x3.1. Since AOP (i) is nonzero
only when interval i is active,
Therefore,
Under what conditions is an interval active? If x
this interval is certainly
active. If the algorithm was not in the holding state prior to this step, it would be
after seeing input x i . Similarly, if x i ? i+1the algorithm must be in the free state
during this interval, and so the interval is not active. Finally, if x
2 the state
remains what it has been for interval i \Gamma 1. Furthermore, since i must be odd for this
case to be possible, cannot be i
(and thus x unambiguously
indicates whether interval i is active). In summary, determining whether interval i is
active requires looking at only x i and occasionally x i\Gamma1 . Since the expected amortized
profit of step i depends on whether i is odd or even, we break the analysis up into
these two cases below.
Case 1: i is even. Note that P rob[x
2 , and x i cannot be exactly i+1
which means that with probability 1
interval i is active. Furthermore, R i+1
is independent of whether interval i is active or not, and so
(i)jInterval i is
Case 2: i is odd. Since interval 1 cannot be active, we assume that i - 3. We need
to consider the case in which x
2 , and so
rob[Interval i is active]
Computing the expected amortized cost of interval i is slightly more complex
than in Case 1.
(i)jInterval i is active]
8 M. Y. KAO AND S. R. TATE
A
Combining both cases,
(i)jInterval i is active] \Delta P rob[Interval i is active]
where the first sum accounts for the odd terms of the original sum, and the second
sum accounts for the even terms.
When n is even this sum becomes
which agrees with the claim in the lemma. When n is odd the sum can be simplified
as
which again agrees with the claim in the lemma. The simplified forms follow the fact
that for any odd n - 3 we can bound 1
Combining this result with that of x3.1, we see that our on-line algorithm has
expected profit 3=4 of what could be obtained with full knowledge of the future. In
terms of competitive analysis, our algorithm has competitive ratio 4=3, which means
that not knowing the future is not terribly harmful in this problem!
3.3. Optimality of Our On-Line Algorithm. This section proves that algorithm
OP is optimal. We will denote permutations by a small Greek letter with a
subscript giving the size of the permutation; in other words, a permutation on the set
may be denoted ae i or oe i .
A permutation on i items describes fully the first i inputs to our problem, and
given such a permutation we can also compute the permutation described by the first
We will use the notation oe i j i\Gamma1 to denote such a restriction.
This is not just a restriction of the domain of the permutation to
unless oe i restriction will not form a valid permutation.
Upon seeing the ith input, an algorithm may make one of the following moves: it
may make this input a low selection; it may make this input a high selection; or it may
simply ignore the input and wait for the next input. Therefore, any algorithm can
be entirely described by a function which maps permutations (representing inputs
of arbitrary length) into this set of moves. We denote such a move function for
algorithm B by MB , which for any permutation oe i maps MB (oe i ) to an element of the
set f"low"; "high"; "wait"g. Notice that not all move functions give valid algorithms.
For example, it is possible to define a move function that makes two low selections in
a row for certain inputs, even though this is not allowed by our problem.
We define a generic holding state just as we did for our algorithm. An algorithm
is in the holding state at time i if it has made a low selection, but has not yet made a
corresponding high selection. For algorithm B we define the set LB (i) to be the set of
permutations on i items that result in the algorithm being in the holding state after
processing these i inputs. We explicitly define these sets using the move function:
The LB (i) sets are all we need to compute the expected amortized profit for interval
since
i!@ jLB (i)j
ae
We use the above notation and observations to prove the optimality of algorithm OP.
Theorem 3.3. Algorithm OP is an optimal algorithm for the multiple pair selection
problem.
Proof. Since the move functions (which define specific algorithms) work on permu-
tations, we will fix an ordering of permutations in order to compare strategies. We order
permutations first by their size, and then by a lexicographic ordering of the actual
permutations. When comparing two different algorithms B and C, we start enumerating
permutations in this order and count how many permutations cause the same
move in B and C, stopping at the first permutation oe i for which MB (oe i
i.e., the first permutation for which the algorithms make different moves. We call the
M. Y. KAO AND S. R. TATE
number of permutations that produce identical moves in this comparison process the
length of agreement between B and C.
To prove the optimality of our algorithm by contradiction, we assume that it is
not optimal, and of all the optimal algorithms let B be the algorithm with the longest
possible length of agreement with our algorithm OP. Let oe k be the first permutation
in which MB (oe k ) 6= MOP (oe k ). Since B is different from OP at this point, at least
one of the following cases must hold:
(a) oe k j
2 and MB (oe k ) 6= "low" (i.e., algorithm
B is not in the holding state, gets a low rank input, but does not make it a low
selection).
2 and MB (oe k ) 6= "wait" (i.e., algorithm
B is not in the holding state, gets a high rank input, but makes it a low selection
anyway).
(c) oe k j
2 and MB (oe k ) 6= "high" (i.e., algorithm
B is in the holding state, gets a high rank input, but doesn't make it a high selection).
2 and MB (oe k ) 6= "wait" (i.e., algorithm
B is in the holding state, gets a low rank input, but makes it a high selection
anyway).
In each case, we will show how to transform algorithm B into a new algorithm C
such that C performs at least as well as B, and the length of agreement between C
and OP is longer than that between B and OP. This provides the contradiction that
we need.
Case (a): Algorithm C's move function is identical to B's except for the following
values:
"wait" if ae
In other words, algorithm C is the same as algorithm B except that we
"correct B's error'' of not having made this input a low selection. The changes
of the moves on input k is the same as LB (k 1).
It is easily verified that the new sets LC (i) (corresponding to the holding
state) are identical to the sets LB (i) for all i 6= k. The only difference at k is
the insertion of oe k , i.e., LC g.
Let PB and PC be the profits of B and C, respectively. Since their amortized
costs differ only at interval k,
k!@ jLC (k)j
ae k 2LC (k)
ae k (k)A
ae k 2LB (k)
ae k (k)A
ON-LINE DIFFERENCE MAXIMIZATION 11
By one of the conditions of Case (a), oe k
, so we finish this derivation
by noting that
0:
Therefore, the expected profit of algorithm C is greater than that of B.
Case (b): As in Case (a) we select a move function for algorithm C that causes
only one change in the sets of holding states, having algorithm C not make
input k a low selection. In particular, these sets are identical with those of
algorithm B with the one exception that LC g. Analysis
similar to Case (a) shows
0:
Case (c): In this case we select a move function for algorithm C such that LC
resulting in algorithm C selecting input k as a high selection,
and giving an expected profit gain of
0:
Case (d): In this case we select a move function for algorithm C such that LC
resulting in algorithm C not taking input k as a high selection,
and giving an expected profit gain of
0:
In each case, we transformed algorithm B into a new algorithm C that performs
at least as well (and hence must be optimal), and has a longer length of agreement
with algorithm OP than B does. This directly contradicts our selection of B as the optimal
algorithm with the longest length of agreement with OP, and this contradiction
finishes the proof that algorithm OP is optimal.
4. Conclusion. In this paper, we examined a natural on-line problem related
to both financial games and the classic secretary problem. We select low and high
values from a randomly ordered set of values presented in an on-line fashion, with
the goal of maximizing the difference in final ranks of such low/high pairs. We considered
two variations of this problem. The first allowed us to choose only a single
low value followed by a single high value from a sequence of n values, while the
second allowed selection of arbitrarily many low/high pairs. We presented provably
optimal algorithms for both variants, gave tight analyses of the performance of these
algorithms, and analyzed how well the on-line performance compares to the optimal
off-line performance.
Our paper opens up many problems. Two particularly interesting directions are
to consider more realistic input sources and to maximize quantities other than the
difference in rank.


Appendix

. Proof of Expected Final Rank. In this appendix section, we
prove that if an item has relative rank x i among the first i inputs, then its expected
rank r i among all n inputs is given by E[r i jx
M. Y. KAO AND S. R. TATE
Lemma A.1. If a given item has rank x from among the first i inputs, and if the
1st input is uniformly distributed over all possible rankings, then the expected rank
of the given item among the first i inputs is i+2
Proof. If we let R be a random variable denoting the rank of our given item from
among the first i then we see that the value of R depends on the rank of
the 1st input. In particular, if the rank of the 1st input is - x (which happens
with probability x
), then the new rank of our given item will be x + 1. On the
other hand, if the rank of the 1st input is ? x (which happens with probability
the rank of our given item is still x among the first i inputs. Using
this observation, we see that
which is what is claimed in the lemma.
For a fixed position i, the above extension of rank to position
times the rank of the item among the first i inputs. Because of this, we can simply
extend this lemma to the case where x is not a fixed rank but is a random variable,
and we know the expected rank among the first i items.
Corollary A.2. If a given item has expected rank x from among the first i
inputs, and if the i +1st input is uniformly distributed over all possible rankings, then
the expected rank of the given item among the first i inputs is i+2
Simply multiplying together the change in expected rank from among i inputs,
to among and so on up to n inputs, we get
a telescoping product with cancellations between successive terms, resulting in the
following corollary.
Corollary A.3. If a given item has rank x from among the first i inputs, and
if the remaining inputs are uniformly distributed over all possible rankings, then the
expected rank of the given item among all n inputs is n+1



--R

Improved algorithms and analysis for secretary problems and generalizations
Fundamentals of Investments
Probability and Measure
The statistical adversary allows optimal money-making trading strategies
The Theory of Optimal Stop- ping
"secretary problem"
An algorithm for maximizing expected log investment return
Competitive analysis of financial games
Foundations of Finance
The secretary problem and its extensions: A review


The Art of Computer Programming

Choosing the maximum from a sequence with a discount function
Amortized efficiency of list update and paging rules
A secretary problem with finite memory
Recognizing both the maximum and the second maximum of a sequence
Dynamic Programming and Stochastic Control
The Mathematics of Financial Derivatives
--TR

--CTR
Avrim Blum , Tuomas Sandholm , Martin Zinkevich, Online algorithms for market clearing, Proceedings of the thirteenth annual ACM-SIAM symposium on Discrete algorithms, p.971-980, January 06-08, 2002, San Francisco, California
financial games;analysis of algorithms;secretary problem;on-line algorithms