DS and Algorithms (GATE 2011 QUESTION 5)