algorithm for problem 3