cmp algorithms