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-8

Exercise 2.2.1-8

not stated yet in Lean solution written

Rating22
KindK2, decide: say whether a claim holds from the written solution
SectionSection 2.2.1 of Volume 1

The task

Decide whether some permutation of 12…n12\ldots n cannot be obtained with a deque that has no restriction on either end.

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

For n≤4n \le 4, count: there are 2424 permutations of 12341234. How many does the general deque give?

Hint 2

For n=5n = 5, look at permutations that start with 55, and use the shape of the deque from Exercise 2.2.1-7.

Solution

Show the solution

Plan. Small nn has no failures. At n=5n = 5 a failure appears, and it carries over to all larger nn.

Case n≤4n \le 4. A search over all move sequences gives all n!n! permutations. The only permutation of 12341234 that neither restricted deque gives is 42314231, by Exercise 2.2.1-7. The general deque gives it as follows. Insert 11. Insert 22 at the right end. Insert 33 at the left end. Insert 44 at the left end. The deque reads 4 3 1 24\,3\,1\,2. Remove 44 at the left end, then 22 at the right end, then 33 at the left end, then 11. The output is 42314231.

Case n=5n = 5. The permutation 5234152341 cannot be obtained. The car 55 is the last to enter, so all five cars have entered when it leaves. The cars entered in the order 1,…,51, \ldots, 5, each at one of the two ends. So the deque, read from left to right, falls to 11 and then rises, and 55 is at an end. After 55 leaves, the cars 1,2,3,41, 2, 3, 4 stay in an arrangement of the same shape, with 44 at one end. The next car out must be 22, so 22 is at the other end. Say 44 is at the left end. Then 22 is the last car on the right side of 11, so that side holds 22 and nothing else. Car 33 lies on the left side, and the deque is 4 3 1 24\,3\,1\,2. Remove 22. The ends are now 44 and 11, but the output needs 33. This fails. If 44 is at the right end, the mirror image of this argument applies.

The search shows that exactly four permutations of 1234512345 fail: 5132451324, 5134251342, 5231452314, 5234152341.

Case n>5n > 5. Suppose a permutation of nn cars is obtained. Then the cars of any subset leave in the same relative order, by the same moves with the other cars ignored. So a permutation that holds the cars 5,2,3,4,15, 2, 3, 4, 1 in this relative order cannot be obtained. An example is 5 2 3 4 1 6 7…n5\,2\,3\,4\,1\,6\,7 \ldots n. Unobtainable permutations exist for every n≥5n \ge 5.

So the answer is: none for n≤4n \le 4, and yes for every n≥5n \ge 5.

Check

A search over all move sequences gave 1,2,6,24,116,634,37621, 2, 6, 24, 116, 634, 3762 obtainable permutations for n=1,…,7n = 1, \ldots, 7. For n≤4n \le 4 this is n!n!. For n=5n = 5 it is 120−4120 - 4. The four missing permutations of 1234512345 are those listed above.

Remarks

The count 116116 for n=5n = 5 is the start of the data for the open question of Exercise 2.2.1-13.

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.