Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems An Application Oriented Approach Complete Version

Authors: Michael Kifer, Arthur Bernstein, Richard Lewis

2nd Edition

0321268458, 978-0321268457

More Books

Students also viewed these Databases questions

Question

4. What action should Cherita Howard take and why?

Answered: 1 week ago