Exercise · Volume 1 · 2.2.1-7
Exercise 2.2.1-7
not stated yet in Lean solution written
| Rating | 25 |
|---|---|
| Kind | K3, find a value: compute a number, a set or a closed form from the written solution |
| Section | Section 2.2.1 of Volume 1 |
The task
Use a deque in place of the stack. Find a permutation of that (a) an input-restricted deque gives and an output-restricted deque does not, (b) an output-restricted deque gives and an input-restricted deque does not, (c) neither of the two 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
Look at permutations that start with . The car is the last car to enter, so all cars have entered before it leaves.
Hint 2
For an input-restricted deque, insert all four cars at the left end. For an output-restricted deque, the four cars sit in the deque in the output order.
Solution
Show the solution
Plan. Study the permutations that start with . They are the same for all three parts.
Let the output start with . Then all of the cars entered before the first removal.
Input-restricted deque. Cars enter at the left only, so the deque reads from left to right. Each further removal takes the largest or the smallest of the cars that remain. So the rest of the output must take, at each step, the maximum or the minimum of what is left.
Output-restricted deque. Cars leave at the left only, so the output is the left to right order of the deque. The cars entered in this order, each at an end. So is somewhere, and each larger car is at the left or right end of the cars before it. The arrangement falls to its minimum and then rises again.
Now test the three permutations.
(a) . For the input-restricted deque: after comes (the minimum of ), then (the maximum of ), then . It works. For the output-restricted deque the arrangement is not a fall and a rise, because it rises from to and then falls to . So it fails.
(b) . For the output-restricted deque: insert , then at the left, then at the right, then at the left. The deque is , and removing at the left gives . For the input-restricted deque: after comes , but is neither the maximum nor the minimum of . So it fails.
(c) . For the input-restricted deque: after comes , which is neither the maximum nor the minimum of . For the output-restricted deque: the arrangement falls, rises, and falls again. Both fail.
So the answers are (a) , (b) , (c) . The search below shows that each of them is the only answer for its part.
Check
I generated all permutations of for both machines by search. The input-restricted set has permutations, and so has the output-restricted set. The first minus the second is . The second minus the first is . The only permutation that is in neither is .
Remarks
Both restricted deques give permutations of , so the count does not separate them. Exercise 2.2.1-9 explains why the counts are equal for every .
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.