On this page
Write the numbers 1 to n in some order and you have a permutation. Pattern avoidance asks whether any group of its entries sits in a forbidden order. It describes exactly which lists one stack can sort.
What does it mean for a permutation to contain 231?
A permutation contains a pattern when some of its entries, not necessarily next to each other, have the same relative order as the pattern (Permutation pattern, Wikipedia). For 231, that means three entries x, y, z appearing in that order with z < x < y: a middle value, then a higher one, then a lower one.
Take 2 4 1 3. The entries 2, 4, 1 go middle, highest, lowest, so 2 4 1 3 contains 231. Now take 3 1 2 5 4. After 3 the larger entries are 5 and 4, and nothing after them is smaller than 3; after 2 comes 5, then only 4. No triple works, so 3 1 2 5 4 avoids 231.
Why can a single stack sort exactly the 231-avoiding permutations?
A stack is a pile where you can only add to or take from the top. The problem of sorting with one stack was first posed by Donald Knuth in 1968, in volume 1 of The Art of Computer Programming, with this rule (Stack-sortable permutation, Wikipedia):
Read the next input value x.
While the stack is not empty and x is larger than the top item, pop the top item to the output.
Push x onto the stack.
When the input runs out, pop everything to the output.
Trace 3 1 2 5 4. Push 3, push 1. Then 2 arrives: pop 1, push 2. Then 5 arrives: pop 2, pop 3, push 5. Then 4 is pushed, and at the end 4 and 5 are popped. The output is 1 2 3 4 5.
Now trace 2 4 1 3. Push 2. Then 4 arrives, so 2 is popped to the output before 1 has even arrived. The triple 2, 4, 1 is what broke it: the higher value forces the middle one out before the lowest one shows up.
Knuth showed that this method sorts exactly the 231-avoiding permutations, and that if it fails, no single stack can sort that input (Stack-sortable permutation, Wikipedia).
Why does every pattern of length 3 give the Catalan numbers?
Write each push as "(" and each pop as ")". Sorting a stack-sortable permutation gives a balanced string of brackets, and every balanced string comes from exactly one such permutation (Stack-sortable permutation, Wikipedia). So the 231-avoiding permutations of length n are counted by the Catalan number C(n) = (2n)! / (n! (n+1)!), which runs 1, 1, 2, 5, 14, 42, 132 (OEIS A000108).
The other five patterns follow. Reversing a permutation, replacing each value x by n + 1 - x, or doing both turns 231-avoiders into 132-, 213- and 312-avoiders, so those three give the same counts (Stack-sortable permutation, Wikipedia). The patterns 123 and 321 are mirror images of each other; Percy MacMahon counted the 123-avoiders with the Catalan numbers in 1915, and Rodica Simion and Frank Schmidt gave the first bijective proof that 123- and 231-avoiders are equal in number in their 1985 paper Restricted permutations80052-4) (Permutation pattern, Wikipedia).
What is the Stanley-Wilf limit?
Richard Stanley and Herbert Wilf conjectured in the late 1980s that for every pattern, the number of permutations of length n avoiding it grows at most like C to the power n for some constant C (Stanley-Wilf conjecture, Wikipedia). Adam Marcus and Gabor Tardos proved it in 2004 in Excluded permutation matrices and the Stanley-Wilf conjecture. The Stanley-Wilf limit of a pattern is the limit of the n-th root of that count.
For any pattern of length 3 the limit is 4, because C(n) is roughly 4 to the power n divided by (n + 1) times the square root of pi n (OEIS A000108). Length 4 is harder: no non-recursive formula is known for the 1324-avoiders, and their limit is only known to lie between 10.271 and 13.5 (Enumerations of specific permutation classes, Wikipedia).
How can you practise pattern avoidance by hand?
List all 24 orderings of 1, 2, 3, 4 and cross out every one containing 231. You should keep 14, the next Catalan number.
Run the stack rule on three of the survivors and one of the crossed-out ones. Write the stack after every step.
For the failure, circle the three entries forming 231 and mark when the middle value was forced out.
Turn each successful run into brackets and check they balance.
For related counting ideas, read the ballot problem and the reflection principle, the hook length formula for Young tableaux and why the 15 puzzle with 14 and 15 swapped can't be solved.
If the definitions of permutations, stacks or bijections are shaky, the Fermi Concept Library gives each concept its own lesson and shows where it fits among the others. To practise counting problems with every step explained, try the Fermi Problem Library, whose solver explains the reasoning rather than printing an answer.



