Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Batcher's sort is mergesort with Batcher's merge.</p> <p>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.</p> <p>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.</p> <p>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</p> <pre><code>0^a 1^b 0^c = 0 ... a copies ... 0 1 ... b copies ... 1 0 ... c copies ... 0 (rotate right by c positions) </code></pre> <p>and</p> <pre><code>1^a 0^b 1^c (rotate left by a positions) </code></pre> <p>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:</p> <pre><code>A = 0^w B = 1^x 0^y 1^z </code></pre> <p>or</p> <pre><code>A = 0^w 1^x B = 1^y 0^z </code></pre> <p>or</p> <pre><code>A = 0^w 1^x 0^y B = 1^z </code></pre> <p>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.</p> <p>The only nontrivial cases are</p> <pre><code>A = 0^w 1^x B = 1^y 0^z </code></pre> <p>and its complement. If w >= y, then A, B become</p> <pre><code>A = 0^(w+x) B = 1^y 0^(w-y) 1^x </code></pre> <p>so A is all zeros and B is bitonic. If w &lt; y, then </p> <pre><code>A = 0^w 1^(y-w) 0^z B = 1^(y+z) </code></pre> <p>so B is all ones, and A is bitonic. If we recursively sort A and B, then their concatenation is the sorted array.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload