homework 4 of algorithm 1 on coursera