[This page is auto-generated; please prefer to read the article’s PDF Form.]
When algorithm A begins, each of the n! permutations can possibly be the sorted permutation. When A makes its 1st comparison between some elements ai and aj, if the order comes out to be ai < aj (say), the best it “knows” is that any permutation in which ai appears after aj cannot be the sorted one. Thus, after this comparison, A is left with all those permutations in which ai appears before aj, and each of these again can possibly be the sorted one. It is only by another comparison between some elements that A would perhaps be further reducing this left-out set of permutations.
Thus, at any point during execution of A, there is a set of permutations each of which can possibly be the sorted permutation, and the sorted permutation must belong to this set. We will call this set the “set of candidate permutations”, and denote it as S. By a sequence of comparisons, A keeps gathering “knowledge” about the elements’ order, which effectively keeps reducing S, until it is left with only 1 permutation in S; this single permutation must be the sorted one.
What we have discussed above is only a model of the algorithm A; it may be called a Model of Candidate Permutations. Many examples of A, like Insertion Sort and Quick Sort, do not actually maintain any set of candidate permutations. The “knowledge” they gather by doing comparisons is recorded by them in the form of their program state, like a sorted subarray or array partitions created based on a pivot. The partial sorted order thus recorded is in fact a representation of the set of candidate permutations.
The above described model of A can be expressed as below. ai is represented as a_i and aj as a_j. P is the set of all permutations in S with ai occurring before aj, and Q is the set of all the remaining ones (S ∖ P).
Note that after any k number of iterations, each permutation in S is consistent with the output of all k comparisons made so far. For example, if two of these comparisons returned a2 < a1 and a5 < a2, each permutation in S must have a5 appearing before a2, and a2 appearing before a1.
Also, since subsets P and Q are simply two partitions of set S, the larger of P and Q must have cardinality at least |S|∕2.
This model of algorithm A extracts from A only its sequence of comparisons and attaches to that sequence a set S of all permutations possible under the comparison responses gathered so far. As long as S contains more than one permutation, A has no way to tell the correct sorted permutation; if it makes any “guess”, that can be wrong. So, A cannot terminate until S has only one permutation left.
Copyright © 2021 Nitin Verma. All rights reserved.