To show that this method sorts an m-near-sorted array
A, we make use of the zero-one principle for sorting networks
(which also applies to data-oblivious sorting algorithms):Theorem 2.1 (Knuth [24]): A sorting network (or dataoblivious
sorting algorithm) correctly sorts all sequences of
arbitrary inputs if and only if it correctly sorts all sequences
of 0-1 inputs.
The main idea behind this principle is that it allows us to
reduce each case of distinguishing the k largest elements and
the n−k smallest elements to an instance having k ones and
n − k zeroes. This allows us to easily prove the following:
Lemma 2.1: Given an m-near-sorted array A of size n, and
a 2m-sorter S, running in T(m) time, a S-shaker pass over
A will sort A in O(T(m)n/m) time.