Given a polynomial $P(x)$ of degree $N$, evaluate $P(x) \bmod M$ at $x = 0$ to $M-1$, where $M$ is a prime number of order $10^6$. Can we do any better than $O(NM)$ given the constraints we only need the value $P(x) \bmod M$?
Asked
Active
Viewed 759 times
1 Answers
2
The answer given at Multi-point evaluations of a polynomial mod p actually answers the question.
Given a primitive root g of M, it is possible to evaluate $P (g^0), P (g^1), \ldots, P (g^{M-1})$ in $O (\max (N, M) \log \max (N, M))$ steps, and then you just rearrange the resulting values and add $P (0)$ which is just the constant coefficient of the polynomial $P$.
Thanks D.W. for the link. The answer given there says that for an arbitrary set of points evaluating all the polynomial values faster than $N$ times number of points can't be done, but of course the result above is useful whenever the number of points is substantially more than $N \log N$.
gnasher729
- 32,238
- 36
- 56