Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
The problem
Fast Homing
Slow Homing
Counting bad cases
A greedy sorting algorithm
Sergi Elizalde
Peter Winkler
Dartmouth College
Rutgers Experimental Mathematics Seminar
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
The homing algorithm
Given a permutation π, repeat the following placement step:
◮
Choose an entry π(i ) such that π(i ) 6= i .
◮
Place π(i ) in the correct position.
◮
Shift the other entries as necessary.
3
5
6
1
8
4
7
2
3
6
1
8
5
4
7
2
3
2
6
1
8
5
4
7
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Main questions
◮
Does the algorithm always finish?
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Main questions
◮
Does the algorithm always finish?
Sergi Elizalde, Peter Winkler
YES
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Main questions
◮
◮
Does the algorithm always finish?
YES
How many steps does it take in the worst case. . .
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Main questions
◮
◮
Does the algorithm always finish?
YES
How many steps does it take in the worst case. . .
◮
◮
◮
with a good choice of placements?
with a random choice of placements?
with a bad choice of placements?
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
“Motivation”
◮
Makes sense when sorting physical objects, such as billiard
balls.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
“Motivation”
◮
Makes sense when sorting physical objects, such as billiard
balls.
◮
In hand-sorting files, it is common to take the first file and
move it to the front, then the second, and so on. This is a
(fast) special case of homing.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
“Motivation”
◮
Makes sense when sorting physical objects, such as billiard
balls.
◮
In hand-sorting files, it is common to take the first file and
move it to the front, then the second, and so on. This is a
(fast) special case of homing.
◮
It is fun to analyze this algorithm.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
“Motivation”
◮
Makes sense when sorting physical objects, such as billiard
balls.
◮
In hand-sorting files, it is common to take the first file and
move it to the front, then the second, and so on. This is a
(fast) special case of homing.
◮
It is fun to analyze this algorithm.
◮
If you have to sort a list and you are paid by the hour, this is
a great algorithm to use.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
History
◮
Despite its simplicity, it seems not to have been considered in
the literature.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
History
◮
Despite its simplicity, it seems not to have been considered in
the literature.
◮
Barry Cipra was looking at a variation of an algorithm of John
H. Conway. In Cipra’s algorithm, after each placement, the
intervening entries are reversed (instead of shifted). This
algorithm does not necessarily terminate:
71325684 → 71348652 → 56843172 → 52713486 →
52317486 → 71325486 → 71325684
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
History
◮
Despite its simplicity, it seems not to have been considered in
the literature.
◮
Barry Cipra was looking at a variation of an algorithm of John
H. Conway. In Cipra’s algorithm, after each placement, the
intervening entries are reversed (instead of shifted). This
algorithm does not necessarily terminate:
71325684 → 71348652 → 56843172 → 52713486 →
52317486 → 71325486 → 71325684
◮
Loren Larson misunderstood the definition of the algorithm,
and thought the intervening numbers were shifted.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
History (cont’d)
Noam Elkies gave a neat proof that homing always terminates:
◮
Suppose it doesn’t. Then there is a cycle, since there are only
finitely many states.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
History (cont’d)
Noam Elkies gave a neat proof that homing always terminates:
◮
Suppose it doesn’t. Then there is a cycle, since there are only
finitely many states.
◮
Let k be the largest number which is placed upward in the
cycle.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
History (cont’d)
Noam Elkies gave a neat proof that homing always terminates:
◮
Suppose it doesn’t. Then there is a cycle, since there are only
finitely many states.
◮
Let k be the largest number which is placed upward in the
cycle.
◮
Once k is placed, it can be dislodged upward and placed again
downward, but nothing can ever push it below position k.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
History (cont’d)
Noam Elkies gave a neat proof that homing always terminates:
◮
Suppose it doesn’t. Then there is a cycle, since there are only
finitely many states.
◮
Let k be the largest number which is placed upward in the
cycle.
◮
Once k is placed, it can be dislodged upward and placed again
downward, but nothing can ever push it below position k.
◮
Hence it can never again be placed upward, a contradiction.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Well-chosen placements
Theorem
◮
An algorithm that always places the smallest or largest
available number will terminate in at most n−1 steps.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Well-chosen placements
Theorem
◮
An algorithm that always places the smallest or largest
available number will terminate in at most n−1 steps.
◮
Let k be the length of the longest increasing subsequence in π.
Then no sequence of fewer than n−k placements can sort π.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Well-chosen placements
Theorem
◮
An algorithm that always places the smallest or largest
available number will terminate in at most n−1 steps.
◮
Let k be the length of the longest increasing subsequence in π.
Then no sequence of fewer than n−k placements can sort π.
◮
The permutation n . . . 21 is the only one requiring n−1 steps.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Random placements
Theorem
The expected number of steps required by random homing from
2
π ∈ Sn is at most n +n−2
.
4
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Random placements
Theorem
The expected number of steps required by random homing from
2
π ∈ Sn is at most n +n−2
.
4
Proof.
◮
Suppose that we have a permutation where k of the extremal
numbers are home:
123746589
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Random placements
Theorem
The expected number of steps required by random homing from
2
π ∈ Sn is at most n +n−2
.
4
Proof.
◮
Suppose that we have a permutation where k of the extremal
numbers are home:
123746589
◮
With probability ≥
extremal number.
2
n−k ,
the next step will place an additional
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Random placements
Theorem
The expected number of steps required by random homing from
2
π ∈ Sn is at most n +n−2
.
4
Proof.
◮
Suppose that we have a permutation where k of the extremal
numbers are home:
123746589
◮
With probability ≥
extremal number.
◮
Total expected number of steps is ≤
2
n−k ,
the next step will place an additional
Sergi Elizalde, Peter Winkler
Pn−2
k=0
n−k
2 .
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
Slow Homing: Example
Starting from
234567... n1
place always the leftmost possible entry:
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
Slow Homing: Example
Starting from
234567... n1
place always the leftmost possible entry:
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
Slow Homing: Example
Starting from
234567... n1
place always the leftmost possible entry:
324567...n1
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
Slow Homing: Example
Starting from
234567... n1
place always the leftmost possible entry:
324567...n1
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
Slow Homing: Example
Starting from
234567... n1
place always the leftmost possible entry:
324567...n1
243567...n1
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
Slow Homing: Example
Starting from
234567... n1
place always the leftmost possible entry:
324567...n1
243567...n1
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
Slow Homing: Example
Starting from
234567... n1
place always the leftmost possible entry:
324567...n1
243567...n1
423567...n1
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
Slow Homing: Example
Starting from
234567... n1
place always the leftmost possible entry:
324567...n1
243567...n1
423567...n1
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
Slow Homing: Example
Starting from
234567... n1
place always the leftmost possible entry:
324567...n1
243567...n1
423567...n1
235467...n1
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
Slow Homing: Example
Starting from
234567... n1
place always the leftmost possible entry:
324567...n1
243567...n1
423567...n1
235467...n1
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
Slow Homing: Example
Starting from
234567... n1
place always the leftmost possible entry:
324567...n1
243567...n1
423567...n1
235467...n1
325467...n1
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
Slow Homing: Example
Starting from
234567... n1
place always the leftmost possible entry:
324567...n1
243567...n1
423567...n1
235467...n1
325467...n1
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
Slow Homing: Example
Starting from
234567... n1
place always the leftmost possible entry:
324567...n1
243567...n1
423567...n1
235467...n1
325467...n1
253467...n1
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
Slow Homing: Example
Starting from
234567... n1
place always the leftmost possible entry:
324567...n1
243567...n1
423567...n1
235467...n1
325467...n1
253467...n1
It takes 2n−1 −1 steps to sort this permutation.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
Main result
Theorem
Homing always terminates in at most 2n−1 −1 steps.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
Main result
Theorem
Homing always terminates in at most 2n−1 −1 steps.
To prove this, consider the reverse algorithm.
We will show that, starting from the identity permutation, one can
perform at most 2n−1 −1 displacements.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
Main result
Theorem
Homing always terminates in at most 2n−1 −1 steps.
To prove this, consider the reverse algorithm.
We will show that, starting from the identity permutation, one can
perform at most 2n−1 −1 displacements.
2n−1 −1 =
n−2
2n−2
+
|{z}
|2 {z− 1}
until 1 and n are displaced after displacing 1 and n
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
Lemma
After 2n−2 displacements, both 1 and n have been displaced and
will never be displaced again.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
Lemma
After 2n−2 displacements, both 1 and n have been displaced and
will never be displaced again.
Proof.
◮
Note that 1 and n can each be displaced only once.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
Lemma
After 2n−2 displacements, both 1 and n have been displaced and
will never be displaced again.
Proof.
◮
Note that 1 and n can each be displaced only once.
◮
If after 2n−2 displacements one of these values hasn’t been
displaced, then it played no role in the process.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
Lemma
After 2n−2 displacements, both 1 and n have been displaced and
will never be displaced again.
Proof.
◮
Note that 1 and n can each be displaced only once.
◮
If after 2n−2 displacements one of these values hasn’t been
displaced, then it played no role in the process.
◮
Hence the remaining n−1 numbers allowed more than 2n−2 −1
steps, contradicting the induction hypothesis.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The code of a permutation
Assume now that 1 and n have both been displaced.
We’ll show that only 2n−2 −1 more displacements can occur.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The code of a permutation
Assume now that 1 and n have both been displaced.
We’ll show that only 2n−2 −1 more displacements can occur.
Assign to each permutation π a code α(π) = α2 α3 . . . αn−1 , where
exactly
0
αi =
+
if entry i is
to the right of
home.
−
to the left of
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The code of a permutation
Assume now that 1 and n have both been displaced.
We’ll show that only 2n−2 −1 more displacements can occur.
Assign to each permutation π a code α(π) = α2 α3 . . . αn−1 , where
exactly
0
αi =
+
if entry i is
to the right of
home.
−
to the left of
Example
π = 35618472
−→
α(π) =
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The code of a permutation
Assume now that 1 and n have both been displaced.
We’ll show that only 2n−2 −1 more displacements can occur.
Assign to each permutation π a code α(π) = α2 α3 . . . αn−1 , where
exactly
0
αi =
+
if entry i is
to the right of
home.
−
to the left of
Example
π = 35618472
−→
α(π) = +
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The code of a permutation
Assume now that 1 and n have both been displaced.
We’ll show that only 2n−2 −1 more displacements can occur.
Assign to each permutation π a code α(π) = α2 α3 . . . αn−1 , where
exactly
0
αi =
+
if entry i is
to the right of
home.
−
to the left of
Example
π = 35618472
−→
α(π) = + −
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The code of a permutation
Assume now that 1 and n have both been displaced.
We’ll show that only 2n−2 −1 more displacements can occur.
Assign to each permutation π a code α(π) = α2 α3 . . . αn−1 , where
exactly
0
αi =
+
if entry i is
to the right of
home.
−
to the left of
Example
π = 35618472
−→
α(π) = + − +
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The code of a permutation
Assume now that 1 and n have both been displaced.
We’ll show that only 2n−2 −1 more displacements can occur.
Assign to each permutation π a code α(π) = α2 α3 . . . αn−1 , where
exactly
0
αi =
+
if entry i is
to the right of
home.
−
to the left of
Example
π = 35618472
−→
α(π) = + − + −
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The code of a permutation
Assume now that 1 and n have both been displaced.
We’ll show that only 2n−2 −1 more displacements can occur.
Assign to each permutation π a code α(π) = α2 α3 . . . αn−1 , where
exactly
0
αi =
+
if entry i is
to the right of
home.
−
to the left of
Example
π = 35618472
−→
α(π) = + − + − −
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The code of a permutation
Assume now that 1 and n have both been displaced.
We’ll show that only 2n−2 −1 more displacements can occur.
Assign to each permutation π a code α(π) = α2 α3 . . . αn−1 , where
exactly
0
αi =
+
if entry i is
to the right of
home.
−
to the left of
Example
π = 35618472
−→
α(π) = + − + − − 0
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The weight of a code
α= + − + − − 0
Define the weight of a code α recursively:
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The weight of a code
α= + − + − − 0
5 1 3 3 4
Define the weight of a code α recursively:
◮
For each −, count the number of symbols to its left, and
for each +, count the number of symbols to its right.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The weight of a code
α= + − + − − 0
5 1 3 3 4
α̂ =
− + − − 0
Define the weight of a code α recursively:
◮
For each −, count the number of symbols to its left, and
for each +, count the number of symbols to its right.
◮
Let d be the largest of these numbers, and let α̂ be the code
obtained by deleting the corresponding symbol.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The weight of a code
α= + − + − − 0
5 1 3 3 4
α̂ =
− + − − 0
Define the weight of a code α recursively:
◮
For each −, count the number of symbols to its left, and
for each +, count the number of symbols to its right.
◮
Let d be the largest of these numbers, and let α̂ be the code
obtained by deleting the corresponding symbol.
◮
Define
w (α) = 2d + w (α̂).
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The weight of a code: example
w( + − + − − 0 )
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The weight of a code: example
w( + − + − − 0 )
5 1 3 3 4
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The weight of a code: example
w( + − + − − 0 )
5 1 3 3 4
= 25 + w ( − + − − 0 )
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The weight of a code: example
w( + − + − − 0 )
5 1 3 3 4
= 25 + w ( − + − − 0 )
0 3 2 3
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The weight of a code: example
w( + − + − − 0 )
5 1 3 3 4
= 25 + w ( − + − − 0 )
0 3 2 3
= 25 + 23 + w ( − + − 0 )
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The weight of a code: example
w( + − + − − 0 )
5 1 3 3 4
= 25 + w ( − + − − 0 )
0 3 2 3
= 25 + 23 + w ( − + − 0 )
0 2 2
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The weight of a code: example
w( + − + − − 0
5 1 3 3 4
= 25 + w ( − + − −
0 3 2 3
= 25 + 23 + w ( − + −
0 2 2
= 25 + 23 + 22 + w ( − +
Sergi Elizalde, Peter Winkler
)
0)
0)
0)
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The weight of a code: example
w( + − + − − 0
5 1 3 3 4
= 25 + w ( − + − −
0 3 2 3
= 25 + 23 + w ( − + −
0 2 2
= 25 + 23 + 22 + w ( − +
0 1
Sergi Elizalde, Peter Winkler
)
0)
0)
0)
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The weight of a code: example
w( + − + − − 0 )
5 1 3 3 4
= 25 + w ( − + − − 0 )
0 3 2 3
= 25 + 23 + w ( − + − 0 )
0 2 2
= 25 + 23 + 22 + w ( − + 0 )
0 1
5
3
2
1
= 2 + 2 + 2 + 2 + w( − 0 )
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The weight of a code: example
w( + − + − − 0 )
5 1 3 3 4
= 25 + w ( − + − − 0 )
0 3 2 3
= 25 + 23 + w ( − + − 0 )
0 2 2
= 25 + 23 + 22 + w ( − + 0 )
0 1
5
3
2
1
= 2 + 2 + 2 + 2 + w( − 0 )
0
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The weight of a code: example
w( + − + − − 0 )
5 1 3 3 4
= 25 + w ( − + − − 0 )
0 3 2 3
= 25 + 23 + w ( − + − 0 )
0 2 2
= 25 + 23 + 22 + w ( − + 0 )
0 1
5
3
2
1
= 2 + 2 + 2 + 2 + w( − 0 )
0
= 25 + 23 + 22 + 21 + 20 + w ( 0 )
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The weight of a code: example
w( + − + − − 0 )
5 1 3 3 4
= 25 + w ( − + − − 0 )
0 3 2 3
= 25 + 23 + w ( − + − 0 )
0 2 2
= 25 + 23 + 22 + w ( − + 0 )
0 1
5
3
2
1
= 2 + 2 + 2 + 2 + w( − 0 )
0
= 25 + 23 + 22 + 21 + 20 + w ( 0 )
= 25 + 23 + 22 + 21 + 20 = 47
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
Bound on the weight
Lemma
The maximum of w (α) over codes α of length k is 2k − 1, for
codes of the form + + · · · + − − · · · −.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
Bound on the weight
Lemma
The maximum of w (α) over codes α of length k is 2k − 1, for
codes of the form + + · · · + − − · · · −.
Proof.
In the recursion,
w (α) ≤ 2k−1 + w (α̂),
with equality when a − is deleted from the right or a + from the
left.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The weight increases at each displacement
Lemma
Let π ∈ Sn with π(1) 6= 1 and π(n) 6= n, and let π ′ be the result of
applying some displacement to π. Let α = α(π) and α′ = α(π ′ ).
Then
w (α′ ) > w (α).
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The weight increases at each displacement
Lemma
Let π ∈ Sn with π(1) 6= 1 and π(n) 6= n, and let π ′ be the result of
applying some displacement to π. Let α = α(π) and α′ = α(π ′ ).
Then
w (α′ ) > w (α).
Proof sketch.
◮
A number i can be displaced iff αi = 0 in the code.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The weight increases at each displacement
Lemma
Let π ∈ Sn with π(1) 6= 1 and π(n) 6= n, and let π ′ be the result of
applying some displacement to π. Let α = α(π) and α′ = α(π ′ ).
Then
w (α′ ) > w (α).
Proof sketch.
◮
A number i can be displaced iff αi = 0 in the code.
◮
If it is displaced to the left, then αi becomes a −, and some
entries αj with j < i can change from − to 0 or from 0 to +.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
The weight increases at each displacement
Lemma
Let π ∈ Sn with π(1) 6= 1 and π(n) 6= n, and let π ′ be the result of
applying some displacement to π. Let α = α(π) and α′ = α(π ′ ).
Then
w (α′ ) > w (α).
Proof sketch.
◮
A number i can be displaced iff αi = 0 in the code.
◮
If it is displaced to the left, then αi becomes a −, and some
entries αj with j < i can change from − to 0 or from 0 to +.
◮
It can be shown that this increases the weight of the code.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
Finishing the proof
Combining these lemmas, the maximum number of
displacements is
◮
at most 2n−2 until 1 and n are displaced, plus
◮
at most 2n−2 −1 after 1 and n have been displaced.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
Example
Main Theorem
Proof: Stage 1
Proof: Stage 2
Finishing the proof
Combining these lemmas, the maximum number of
displacements is
◮
at most 2n−2 until 1 and n are displaced, plus
◮
at most 2n−2 −1 after 1 and n have been displaced.
So at most 2n−1 −1 in total.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
The number of worst-case permutations
h(π) = max. length of a seq. of placements from π to 12 . . . n.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
The number of worst-case permutations
h(π) = max. length of a seq. of placements from π to 12 . . . n.
Mn = {π ∈ Sn : h(π) = 2n−1 −1}.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
The number of worst-case permutations
h(π) = max. length of a seq. of placements from π to 12 . . . n.
Mn = {π ∈ Sn : h(π) = 2n−1 −1}.
For example, 23 . . . n1 ∈ Mn .
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
The number of worst-case permutations
h(π) = max. length of a seq. of placements from π to 12 . . . n.
Mn = {π ∈ Sn : h(π) = 2n−1 −1}.
For example, 23 . . . n1 ∈ Mn .
Theorem
Bn−1 ≤ |Mn | ≤ (n − 1)!,
where Bn = n-th Bell number = # partitions of {1, 2, . . . , n}.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
The number of worst-case permutations
h(π) = max. length of a seq. of placements from π to 12 . . . n.
Mn = {π ∈ Sn : h(π) = 2n−1 −1}.
For example, 23 . . . n1 ∈ Mn .
Theorem
Bn−1 ≤ |Mn | ≤ (n − 1)!,
where Bn = n-th Bell number = # partitions of {1, 2, . . . , n}.
Bn grows super-exponentially:
1
Bn ∼ √ λ(n)n+1/2 e λ(n)−n−1 ,
n
where λ(n) =
n
W (n) ,
and W (n)e W (n) = n.
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
The number of worst-case permutations
fi ,j = |{π ∈ Mi +j : α(π) = +
· · · +} −
· · · −}}|
| +{z
| −{z
i −1
Sergi Elizalde, Peter Winkler
j−1
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
The number of worst-case permutations
fi ,j = |{π ∈ Mi +j : α(π) = +
· · · +} −
· · · −}}|
| +{z
| −{z
i −1
F (u, v ) =
X
j−1
fi ,j u i v j
i ,j≥1
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
The number of worst-case permutations
fi ,j = |{π ∈ Mi +j : α(π) = +
· · · +} −
· · · −}}|
| +{z
| −{z
i −1
F (u, v ) =
X
j−1
fi ,j u i v j
i ,j≥1
|Mn | =
P
i +j=n fi ,j
is the coefficient of t n in F (t, t).
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
The number of worst-case permutations
fi ,j = |{π ∈ Mi +j : α(π) = +
· · · +} −
· · · −}}|
| +{z
| −{z
i −1
F (u, v ) =
X
j−1
fi ,j u i v j
i ,j≥1
|Mn | =
P
i +j=n fi ,j
is the coefficient of t n in F (t, t).
Theorem
F (u, v ) = uv + uv
∂
∂
∂2
F (u, v ) + uv F (u, v ) − u 2 v 2
F (u, v )
∂u
∂v
∂u∂v
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
1 2 3 4 5
23451
34251
34521
34512
32451
43521
45213
24513
45231
45321
24531
45132
45312
53412
42513
43251
42531
53142
42351
23514
35214
35421
23541
32514
35241
53421
32541
25431
54321
41253
34215
34125
32415
45123
51324
54213
25413
25134
51342
54231
52413
25143
52134
25314
53214
41352
41532
14532
31452
13452
14523
15423
41325
42153
31542
14352
13524
42135
43215
15432
13542
15324
42315
14253
23154
21453
31254
21534
31425
15342
14235
23145
12453
32154
21543
31245
12534
13425
32145
13254
14325
21354
21435
12543
12354
15234
15243
24135
21345
51234
52143
24315
13245
51423
52314
41523
31524
54123
51243
35124
35142
52341
24153
54312
53241
34152
43125
35412
51432
52431
43152
41235
54132
53124
24351
25341
23415
43512
12435
12345
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm
The problem
Fast Homing
Slow Homing
Counting bad cases
1 2 3 4 5
23451
34251
34521
34512
32451
24513
45231
45321
43512
24531
45132
45312
53412
42513
43251
42531
53142
42351
23514
35214
35421
23541
32514
35241
53421
32541
25431
54321
25341
41253
34215
34125
32415
41235
43125
45123
51324
54213
25413
25134
51342
54231
52413
25143
52134
25314
53214
41352
31524
31452
13452
14523
15423
41325
42153
31542
14352
13524
42135
43215
15432
13542
15324
42315
14253
23154
21453
31254
21534
31425
15342
14235
23145
12453
32154
21543
31245
12534
13425
32145
13254
14325
21354
21435
12543
21345
12354
15234
15243
24135
24315
13245
51234
YOU
41532
14532
51423
52143
52314
41523
54123
51243
35124
35142
52341
24153
54312
53241
34152
35412
51432
52431
43152
54132
53124
24351
THANK
23415
43521
45213
12435
12345
Sergi Elizalde, Peter Winkler
A greedy sorting algorithm