algorithms 2 581