a1 algorithm