Exercise · Volume 1 · 2.2.1-5
Exercise 2.2.1-5
not stated yet in Lean solution written
| Rating | M28 |
|---|---|
| Markers | M (mathematical) |
| Kind | K1, prove: show that a stated fact is true from the written solution |
| Section | Section 2.2.1 of Volume 1 |
The task
Show that can be obtained from with a stack if and only if there are no indices with .
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 the "only if" part, ask when each of the cars and must enter the stack.
Hint 2
For the "if" part, run the following rule. To output , first push input cars until is in the stack. Then pop it. Show that the rule never pops a wrong car.
Solution
Show the solution
Plan. Show that a bad triple forces a contradiction. Then show that, without bad triples, the greedy rule works.
Only if. Suppose and . The cars enter in increasing order, so enters first, then , then . The output has before and . So when leaves, the cars and have entered and have not left. They are in the stack, and lies above . A stack gives up first. But the output has before . This is a contradiction.
If. Let have no bad triple. Use this rule for . If is not yet in the stack, push the next input cars until is pushed. Then pop . The cars enter in increasing order, so the stack always has increasing values from the bottom to the top.
Suppose the rule fails at step . Then is in the stack, and some car lies above it. We have , because the stack increases upward. The car has not left, so for some . The car was pushed during some earlier step , while the rule sought . That step pushes the input up to , and , so . Then with . This is a bad triple, and it does not exist. So the rule never fails, and it ends with the output .
Check
For I compared two sets. The first is the set of all permutations that a stack gives, found by search. The second is the set of permutations with no triple of the type above. The two sets were equal each time, with elements.
Remarks
In the language of patterns, the stack gives exactly the permutations that avoid the pattern . The result also proves again that is the Catalan number, as Exercise 2.2.1-4 finds.
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.