I wrote an exam paper today, for a university course concerned with the implementation of data structures in Java. The last question was along these lines:
Explain why it's convienient to use a TreeMap<Integer, Integer> to store a polynomial with integral coefficients, especially when the polynomial is supposed to be printed out in standard form, as a String.
Realising that it was a mistake, I nevertheless proceeded to explain why I did not think it was a good idea. I instead argued to use a simple int[] array, since arrays have O(1) random access, O(n) iteration in both directions and no extra memory footprint for pointers (references).
Assuming I'm wrong and there is some benefit to using a (sorted) TreeMap, can anyone please explain those benefits to me? I reason that since Matlab, Octave, Maple and other well-tested numerical programs use arrays to store polynomials, it can't be all wrong.