Search code examples
time-complexitypolynomials

How to calculate formally the running time of the naive polynomial evaluation at a point


I understand intuitively why the time complexity of the naive polynomial evaluation at a point is ϴ(n^2). However, I'm not sure how to calculate formally the running time in order to show it.

Thanks in advance!


Solution

  • Not quite ϴ(n^2), but ϴ(mn), where m and n are the number of terms in each polynomial.

    enter image description here

    There are trivially m * n multiplication required, equal to the number of ways to pair coefficients a_i * b_j between the two polynomials.

    There are also additions to consider; however, since any certain pair of coefficients a_i, b_j only belongs to one power of x, it will only be added once to a coefficient in the final polynomial. Therefore there can only be up to O(mn) additions.

    Therefore the overall time complexity of naive multiplication is ϴ(mn).