Here is the solution for the final exam. My comments on common mistakes are embedded inside.
And now, a personal message: I would like to thank all of you for being patient with me throughout the semester. This semester’s CS2105 has been the most difficult semester for me to teach: (i) the class size increases to a record high of 191, (ii) the number of TAs reduces to 1, and (iii) I just become a father to a pair of twins in Dec 2013 and am in the constant state of sleep deprivation for the whole semester. I have been late in posting class materials, returning assignments, and returning emails (or not returning emails). I have made mistakes in some of the lectures and spoken incoherently occasionally, and yet you all have been the nicest bunch of students and have tolerated these. Some of you even have kind words for me despite all of these, and that kept me going. So, thank you.
I hope you have enjoyed CS2105 and have learnt something useful. Have a good break!