some algorithm exercise