classical algorithm