add compare and rank algorithm