algorithm impl and test