This is the assignment given in Class CS 106A of Satnford University.