Code for Part 1 of Algorithms