Question: You are given the coefficients alpha 0 , alpha 1 , . . . , alpha n of a polynomial P (

You are given the coefficients \alpha 0,\alpha 1,...,\alpha n of a polynomial
P(x)= Xn k=0\alpha kxk=\alpha 0+\alpha 1x +\alpha 2x 2++\alpha nxn,
and you want to evaluate this polynomial for a given value of x. Horners rule says to
evaluate the polynomial according to this parenthesization:
P(x)=\alpha 0+ x
\alpha 1+ x
\alpha 2++ x (\alpha n1+ x\alpha n)
.
The procedure Horner implements Horners rule to evaluate P(x), give the coefficients
\alpha 0,\alpha 1,...,\alpha n in an array A[0 : n] and the value of x.
Horner(A, n, x)
1: p 0
2: for i = n to 0 do
3: p A[i]+ x p
4: end for
5: return p
For this problem, assume that addition and multiplication can be done in constant time.
(a) In terms of \Theta -notation, what is the running time of this procedure?
(b) Write pseudocode to implement the naive polynomial-evaluation algorithm that computes each term of the polynomial from scratch. What is the running time of this
algorithm? How does it compare to Horner?
(c) Consider the following loop invariant for the prcedure Horner:
At the start of each iteration of the for loop of lines 2-3,
p =
nX
(i+1)
k=0
A[k + i +1] x
k
.
Interpret a summation with no terms as equaling 0. Following the structure of the loopinvariant proof presented in class, use this loop invariant to show that, at termination,
p =
Pn
k=0 A[k] x
k
.

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!