Full implementation of comparison algorithm.