Implemented the comparison algorithm.