Date of Award


Document Type

Thesis (Undergraduate)


Department of Computer Science

First Advisor

Peter Doyle

Second Advisor

Scot Drysdale


The problem of determining which permutations can be sorted using certain switchyard networks is a venerable problem in computer science dating back to Knuth in 1968. In this work, we are interested in permutations which are sortable on a double-ended queue (called a deque), or on two parallel stacks. In 1982, Rosenstiehl and Tarjan presented an O(n) algorithm for testing whether a given permutation was sortable on parallel stacks. In the same paper, they also presented a modification giving O(n) test for sortability on a deque. We demonstrate a slight error in the version of their algorithm for testing deque sortability, and present a fix for this problem. The general enumeration problem for both of these classes of permutations remains unsolved. What is known is that the growth rate of both classes is approximately Theta(8^n), so computing the number of sortable permutations of length n, even for small values of n, is difficult to do using any method that must evaluate each sortable permutation individually. As far as we know, the number of deque sortable permutations was known only up to n=14. This was computed using algorithms which effectively generate all sortable permutations. By using the symmetries inherent in the execution of Tarjan's algorithm, we have developed a new dynamic programming algorithm which can count the number of sortable permutations in both classes in O(n^5 2^n) time, allowing the calculation of the number of deque and parallel stack sortable permutation for much higher values of n than was previously possible. Finally, we have examined the problem of trying to sort a permutation on a deque when the input elements are only revealed at the time when they are pushed to the deque. (Instead of having an omniscient view of the input permutation, this corresponds to encoding the input permutation as a deck of cards which must be drawn and pushed onto the deque without looking at the remaining cards in the deck.) We show that there are some sortable permutations which cannot necessarily be sorted correctly on a deque using only this imperfect information.


Originally posted in the Dartmouth College Computer Science Technical Report Series, number TR2012-719.