taocp

This site has no text of the book. Keep your own copy of TAOCP next to it. See what is checked.

Exercise · Volume 1 · 2.2.1-9

Exercise 2.2.1-9

not stated yet in Lean solution written

RatingM20
MarkersM (mathematical)
KindK1, prove: show that a stated fact is true from the written solution
SectionSection 2.2.1 of Volume 1

The task

Let bnb_n be the number of permutations of nn elements that an input-restricted deque gives. Show that bnb_n is also the number that an output-restricted deque gives.

The exact wording is in your copy of the book.

Hints

Open one hint at a time. Try the exercise again after each.

Hint 1

Run a sequence of moves backwards in time. Which end of the deque is then the input end?

Hint 2

Write down the permutation that the reversed run gives, after you rename the cars so that the input is 12…n12\ldots n again.

Solution

Show the solution

Plan. Reverse time. A run of one machine becomes a run of the other. The change of names is a bijection of the set of permutations.

Take a run of an input-restricted deque that turns 12…n12\ldots n into p1p2…pnp_1 p_2 \ldots p_n. Cars enter at the left end only. They leave at either end. Play this run backwards. Now the cars enter at the old output ends, so at either end. They leave at the old input end, so at one end only. The cars enter in the order pn,pn−1,…,p1p_n, p_{n-1}, \ldots, p_1 and leave in the order n,n−1,…,1n, n-1, \ldots, 1. This is a run of an output-restricted deque.

Rename the cars so that the input is 1,2,…,n1, 2, \ldots, n. The car pkp_k is the (n+1−k)(n+1-k)-th to enter, so it gets the name n+1−kn+1-k. The car with value vv has the name n+1−p−1(v)n + 1 - p^{-1}(v), where p−1p^{-1} is the inverse permutation. The jj-th car to leave is the one with value n+1−jn+1-j. So the output of the renamed run is the permutation q=φ(p)q = \varphi(p) with qj=n+1−p−1(n+1−j).q_j = n + 1 - p^{-1}(n+1-j).

The map φ\varphi is its own inverse. To see this, note that qj=mq_j = m gives p−1(n+1−j)=n+1−mp^{-1}(n+1-j) = n+1-m, so j=n+1−p(n+1−m)j = n+1 - p(n+1-m), and hence q−1(m)=n+1−p(n+1−m)q^{-1}(m) = n+1-p(n+1-m). Then φ(q)j=n+1−q−1(n+1−j)=pj\varphi(q)_j = n + 1 - q^{-1}(n+1-j) = p_j. So φ\varphi is a bijection of the set of all permutations.

The argument shows that φ\varphi maps every permutation of the input-restricted deque to a permutation of the output-restricted deque. The same argument, with the two machines exchanged, shows that φ\varphi maps every permutation of the output-restricted deque to a permutation of the input-restricted deque. Since φ\varphi is its own inverse, it maps the first set onto the second. So the two sets have the same size.

Check

For n=1,…,7n = 1, \ldots, 7 I computed both sets by search. Both have 1,2,6,22,90,394,18061, 2, 6, 22, 90, 394, 1806 elements. The map φ\varphi sent each set onto the other.

Remarks

For n=4n = 4 the map sends the permutation 41324132 of the input-restricted deque to 42134213, the permutation of the output-restricted deque in Exercise 2.2.1-7.

This solution is drafted, and a person has not reviewed it yet. The source.

In Lean

not stated yet The exercise is not stated in Lean yet.

The status is computed from the Lean build. The node of the map.

Something is wrong? Report it.