Odd-Even Sort in Powerlists

In 6] Misra introduced the powerlist notation and used it to succintly describe several parallel algorithms. In particular, algorithms that use a balanced divide and conquer strategy have elegant descriptions as powerlist functions. Among the examples presented were two sorting networks due to Batcher 1]. To prove their correctness a-posteriori, Misra used the 0-1 principle, which states that a compare-and-swap sorting algorithm is correct ii it sorts all inputs consisting of 0s and 1s. Misra attributed the 0-1 principle to Knuth 3], where Batcher's networks are presented. One of Batcher's networks, the Bitonic Sort, can be derived as a parallel algorithm, as shown by Huang and Lengauer 2]. In this paper we study the odd-even sort which can be considered a parallel version of bubble sort; it is simple to implement and to explain operationally, yet it is ineecient and somewhat tedious to prove correct 0. The algorithm consists of a sequence of phases, where each phase consists of an \even" step followed by an \odd" step. It is often described operationally as follows 5]: At odd steps, we compare the contents of cells 1 and 2, 3 and 4, etc., exchanging values if necessary so that the smaller value ends up in the leftmost cell. At even steps, we perform the same operation for cells 2 and 3, 4 and 5, etc. In this paper we derive the odd-even sort and prove its correctness. In contrast to Batcher's networks, the odd-even sort is iterative in nature and does not have a simple deenition in the powerlist notation. Our derivation is somewhat surprising: from a simple characterization of what it means for a powerlist to be sorted, the algorithm emerges through a series of transformations. The remaining proof of correctness consists of proving that after a nite number of phases of the computation, odd-even sort reaches a xpoint, and that each phase produces a permutation of the input. In contrast to Misra's presentation 6] of Batcher's networks, we derive the odd-even sort, and our proofs of correctness do not use the 0-1 principle. 1 Preliminaries In this paper we use the notation and concepts that exist in the literature on powerlists 0, 4, 6]. As a convenience to the reader we give a brief introduction to the powerlist notation below. A powerlist is a linear data structure, whose elements are all of the same data type. The length of a …