Question: You are given an input integer array P = [ a 0 , a 1 , a 2 , . . . an ] of

You are given an input integer array P =[a0, a1, a2,... an] of length n +1 that stores the coefficients of an n degree polynomial p, and an integer value x. Your goal
is to compute the value of p(x)= a0+ a1x + a2x2+ a3x3+... anxn for an input x. You may
assume that all elementary integer operations (+,-,*,/) take O(1) time.
Consider the following algorithm, and convince yourself that it correctly evaluates the polynomial.
def polyEval(P,x):
ans =0
for i in range(n+1): //0...n
term = P[i]
for j in range(i):
term = term * x
ans = ans + term
return ans
What is the runtime of this algorithm? Choose between stating the answer as big-\Theta or big-O as appropriate, choosing the *most* restrictive answer when possible.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!