Theory of Computing Systems

, Volume 60, Issue 3, pp 552–579

# 2-Stack Sorting is Polynomial

• Dominique Rossin
Article

## Abstract

In this article, we give a polynomial algorithm to decide whether a given permutation σ is sortable with two stacks in series. This is indeed a longstanding open problem which was first introduced by Knuth ([1973]). He introduced the stack sorting problem as well as permutation patterns which arises naturally when characterizing permutations that can be sorted with one stack. When several stacks in series are considered, few results are known. There are two main different problems. The first one is the complexity of deciding if a permutation is sortable or not, the second one being the characterization and the enumeration of those sortable permutations. We hereby prove that the first problem lies in P by giving a polynomial algorithm to solve it. This article relies on Pierrot and Rossin ([2013]) in which 2-stack pushall sorting is defined and studied.

## Keywords

Stack Sort Permutation Pattern Polynomial algorithm Combinatorics Algorithms Permutation patterns Stack-sorting

## Notes

### Conflict of interests

The authors declare that they have no conflict of interest.

### Funding

This study was funded by ANR, project ANR BLAN-0204_07 MAGNUM.

## References

1. 1.
Albert, M., Atkinson, M. D., Linton, S.: Permutations generated by stacks and deques. Ann. Comb. 14, 3–16 (2010)
2. 2.
Atkinson, M. D., Murphy, M. M., Ruskuc, N.: Sorting with two ordered stacks in series. Theor. Comput. Sci. 289, 205–223 (2002)
3. 3.
Bóna, M.: A survey of stack-sorting disciplines. Electron. J. Comb. 9(2), 16 (2003)
4. 4.
Even, S., Itai, A.: Queues, stacks, and graphs. In: Theory of Machines and Computations, pp 71–86. Academic Press (1971)Google Scholar
5. 5.
Kitaev, S.: Patterns in permutations and words. Monographs in theoretical computer science. An EATCS Series, Springer (2011)Google Scholar
6. 6.
Knuth, D. E.: The Art of Computer Programming, Volume I: Fundamental Algorithms. Addison-Wesley (1968)Google Scholar
7. 7.
Knuth, D. E.: The Art of Computer Programming, Volume III: Sorting and Searching. Addison-Wesley (1973)Google Scholar
8. 8.
Murphy, M.M.: Restricted Permutations Antichains, Atomic Classes and Stack Sorting. PhD thesis, University of St Andrews (2002)Google Scholar
9. 9.
Pierrot, A.: Combinatoire et algorithmique dans les classes de permutations. Phd thesis, Université Paris Diderot - Paris 7. (available in English at http://www.normalesup.org/~adpierro/pdf/these_Adeline_Pierrot.pdf) (2013)
10. 10.
Pierrot, A., Rossin, D.: 2-stack pushall sortable permutations. Preprint available at arXiv:1303.4376 (2013)
11. 11.
Tarjan, R. E.: Sorting using networks of queues and stacks. J. ACM 19(2) (1972)Google Scholar
12. 12.
Unger, W.: The complexity of colouring circle graphs (extended abstract). In: Finkel, A., Jantzen, M. (eds.) STACS 92, 9th Annual Symposium on Theoretical Aspects of Computer Science, Cachan, France, February 13–15, 1992, Proceedings, volume 577 of Lecture Notes in Computer Science, pp 389–400. Springer (1992)Google Scholar
13. 13.
West, J.: Sorting twice through a stack. Theor. Comput. Sci. 117(1&2), 303–313 (1993)