views:

30

answers:

1

I'm trying to grasp the concept of a Batcher Sort. However, most resources I've found online focus on proof entirely or on low-level pseudocode. Before I look at proofs, I'd like to understand how Batcher Sort works. Can someone give a high level overview of how Batcher Sort works(particularly the merge) without overly verbose pseudocode(I want to get the idea behind the Batcher Sort, not implement it)? Thanks!

+1  A: 

Batcher's sort is mergesort with Batcher's merge.

To merge two arrays A and B, Batcher's merge concatenates A in forward order with B in reverse order, creating a bitonic array. It then applies Batcher's bitonic sort.

Batcher's bitonic sort is a cousin of quicksort. It divides the array into two halves, does some swaps to ensure that no element in the first half is greater than an element in the second, and recursively sorts the halves.

An array is bitonic if it can be rotated so that its elements increase and then decrease. By the zero-one principle for oblivious sorts, it suffices to prove correctness on zero-one inputs, and we make that assumption now. The possibilities are

0^a 1^b 0^c = 0 ... a copies ... 0 1 ... b copies ... 1 0 ... c copies ... 0 (rotate right by c positions)

and

1^a 0^b 1^c (rotate left by a positions)

where a, b, c are nonnegative integers. The bitonic sort first splits this array in two equal-size halves A and B. There are a couple possibilities:

A = 0^w
B = 1^x 0^y 1^z

or

A = 0^w 1^x
B = 1^y 0^z

or

A = 0^w 1^x 0^y
B = 1^z

or the three others with zero and one interchanged. Batcher's insight is that by applying a comparator for all i to A[i], B[i], either A is all zeros and B is bitonic, or A is bitonic, and B is all ones. Either way, the precondition for the recursive sorts is met.

The only nontrivial cases are

A = 0^w 1^x
B = 1^y 0^z

and its complement. If w >= y, then A, B become

A = 0^(w+x)
B = 1^y 0^(w-y) 1^x

so A is all zeros and B is bitonic. If w < y, then

A = 0^w 1^(y-w) 0^z
B = 1^(y+z)

so B is all ones, and A is bitonic. If we recursively sort A and B, then their concatenation is the sorted array.