UMBC CMSC641, Design & Analysis of Algorithms, Fall 1997
Due: Wednesday, September 10, 1997
- Problem 7-2, page 152.
- Exercise 18.1-3, page 360.
- Railroad Yard Switching:
We are given as input a permutation p(1), p(2), ..., p(n)
of 1, 2, ..., n. We have two stacks, A and B, and we want to
sort the permutation into increasing order using operations of the
It may help to visualize this as a railroad yard switching problem:
- load the next element onto top of stack A
- load the next element onto top of stack B
- move top of stack A to output
- move top of stack B to output
Some permutations can be sorted and others can't. For example,
2314 can, 2341 can't, 5274163 can't and 78524163 can. Design an
algorithm that either reports that it can't be sorted or shows how
to sort it by assigning p(i) to stack A or stack B for
each i. The algorithm should run in time polynomial in n.
How small can you make the exponent of n?
A PostScript version of this assignment (with better typesetting) is also
3 Sep 1997 20:49:47 EDT
to Fall 1997 CMSC 641 Homepage