I think the most striking example is x^10000 + 3x^2 + 2 or something like that. Do you want to make new int[10000] instead of three nodes in TreeMap ? TreeMap
And of course, by sorting, you can iterate to make it easier to create and manipulate your polynomial.
And are you sure arrays are used for numeric programs? I would like to see a quote from their internal implementation, if you think that is the case.
As for the memory problem, the standard implementation of java.util.TreeMap will give 7 additional links and primitives, one of which has a link inside it, the other of which contains 7 links inside it. So you are looking at 15 additional links for this. Each entry will have 5 references and a primitive, so instead of 2 + 1 * n for your array you have 15 + 6 * n. Thus, at any time when you have (14 + 5 * n) empty polynomials, using TreeMap uses less memory than using an array.
The smallest example of this would be x^20 , in which there would be 21 array elements and 1 array reference for a total of 22 words, and TreeMap would contain only 21 words.
It is possible that I lack the link in the implementation, but I went through it pretty well.
source share