Question: You are given the coefficients alpha 0 , alpha 1 , . . . , alpha n of a polynomial P (
You are given the coefficients alpha alpha alpha n of a polynomial
Px Xn kalpha kxkalpha alpha x alpha x
alpha nx
n
and you want to evaluate this polynomial for a given value of x Horners rule says to
evaluate the polynomial according to this parenthesization:
Pxalpha x
alpha x
alpha x alpha n xalpha n
The procedure Horner implements Horners rule to evaluate Px give the coefficients
alpha alpha alpha n in an array A : n and the value of x
HornerA n x
: p
: for i n to do
: p Ai x p
: end for
: 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 polynomialevaluation 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
p
nX
i
k
Ak i x
k
Interpret a summation with no terms as equaling Following the structure of the loopinvariant proof presented in class, use this loop invariant to show that, at termination,
p Pn k Ak xk
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
