apply algorithm