
338 Combinatorics of Permutations, Second Edition
permutation p by such a deque, it is obvious that we have to keep the deque
increasing from top to bottom, which makes the definition of the rest of the
sorting algorithm easy. The reader should try to solve Exercises 24 and 25 for
the details.
Exercises
1. Take a permutation of length n. Assign a direction (Left or Right)
to each entry, such as in 2
L
3
R
4
L
1
R
5
L
.Callanentryx winning if its
neighbor in the direction given to x exists, is y,andy<x.Sofor
instance, in 2
L
3
R
4
L
1
R
5
L
, the entries 4 and 5 are winning.
Now consider the following algorithm. Start with the permutation p
1
=
1
L
2
L
···n
L
. Find the largest winning ...