An economical construction for sorting networks

An <i>N</i>-input <i>sorting network</i>, or an <i>N-sorter</i>, is a switching circuit with <i>N</i> outputs that satisfy the following: for any combination of inputs <i>I</i> = {<i>i</i><sub>a</sub>, <i>i</i><sub>1</sub>, ..., <i>i</i><sub>N-1</sub>}, the resulting outputs 0 = {<i>o</i><sub>0</sub>, <i>o</i><sub>1</sub>, ..., <i>o</i><sub>N-1</sub>} are a permutation of <i>I</i>, and <i>o</i><sub>0</sub>≤<i>o</i><sub>1</sub>≤...;≤<i>o</i><sub>N-1</sub>. Batcher shows that a basic 2-sorter, or <i>comparator</i> cell, can be used to construct <i>N</i>-sorters for arbitrary <i>N</i>. For example, the circuit in Figure 1 is a 4-sorter, since comparators <i>A</i> through <i>D</i> move the smallest input to <i>o</i><sub>0</sub> and the largest input to <i>o</i><sub>3</sub>, and then comparator <i>E</i> orders the remaining two inputs.