# Sorting based on pairwise comparison

## Input

1. An ordered sequence $S$ of length $n$.
2. A definition of comparison on the component type of $S$.

## Output

A permutation of $S$ such that $S[i] \le S[i+1]$ for all $i\in \{1,...,n-1\}$.

N/A

## Complexity

Polynomial if the comparison is polynomial.

## Remark

Some algorithms could be formulated in a much simpler way in case each key occurs at most once in $S$. Here all algorithms are formulated for the general case of arbitrary multiplicities. Alternatively, there are three options to make each key unique:

1. An additional generated key such as, for example, the student ID or the tax file number.
2. If the keys are associated with values, they are additionally compared if the keys of two items are identical (e.g. date of birth and home address, if last and first names of two persons are identical).
3. On the other hand, if the keys are not associated with values, we may remove the duplicates and store their multiplicities separately.