We first prove that if \(\pi\) is stack sortable then it is \(231\)-avoiding. Suppose that the opposite happened, i.e., that there exist \(i\lt j\lt k\) where
\begin{equation*}
\pi_j=b \gt \pi_i=a \gt \pi_k=c \, ,
\end{equation*}
where we use the names \(a,b,c\) to simplify notation. When we get to \(c\) in the stack sorting process, there are several possibilities for what has occurred previously in the process.
-
If
\(a\) or
\(b\) have already been popped from the stack, then that value will appear before
\(c\) in the list, which would result in the final list being out of order. So, we must have both
\(a\) and
\(b\) in the stack when
\(c\) is considered in the sorting process.
-
Note that in the stack when \(c\) is considered, we must have \(a\) below \(b\) in the stack, because \(a\) was pushed onto the stack before \(b\) since \(a\) was considered first in the sorting process:
\begin{equation*}
S=(s_1,\ldots,b,\ldots,a,\ldots,s_k)^T
\end{equation*}
We must pop \(c\) before \(a\) and \(b\text{,}\) and as the process continues, we must pop \(b\) from the stack before we pop \(a\text{.}\) However, this will result in \(b\) appearing before \(a\) in the final list, which would put the elements out of order. Therefore, cannot have a \(231\)-pattern in \(\pi\text{.}\)
We next prove that if
\(\pi\) avoids
\(231\) then it is stack sortable. For any two elements
\(a\) and
\(b\) such that
\(a\) comes before
\(b\) in
\(\pi\text{,}\) if
\(a\gt b\) then there is not a value
\(c\gt a\) between
\(a\) and
\(b\) in
\(\pi\text{.}\) Thus,
\(a\) will enter the stack and will not leave until
\(b\) has left the stack, meaning that
\(b\) will come before
\(a\) in the list, as desired. If
\(a\lt b\text{,}\) then
\(a\) will enter and leave the stack before
\(b\) enters the stack, and again they will appear in the correct order in the list. Since this is true for all pairs
\(a\) and
\(b\text{,}\) the stack sorting procedure will correctly sort the permutation.