Algorithm2