Algorithms homework