I represent a monomial with a 3x2 vector. For example,
x y z : ( (variable id, exponent of variable) )
: ( (1,1) , (2, 1) , (3,1) )
x^2 z^2 : ( (1,2) , (3,2) , (null, null) )
I think you have to loop over the 3x2 vector.
And one could argue that looping over the vector is an O(1) operation. Why? Because the number of entries in the vector is exactly 3, which is a small constant number. To put it another way, the loop count is independent of the big numbers:
nwhich is the number of variables, and
mwhich is the number of monomials.
It doesn't matter how big (or small)
n are, looping over the vector always takes the same amount of time, so it's technically an O(1) operation.