Finished algorithm for problem 2.