Problem

Correctness of Horne’s ruleThe following code fragment implements Horner’s rule for evalua...

Correctness of Horne’s rule

The following code fragment implements Horner’s rule for evaluating a polynomial

given the coefficients a0, a1,…,an and a value for x:

1     y ←0

2     i ← n

3     while i ≥ 0

4                do y ←ai + x ·y

5                       i←i ‒ 1

a. What is the asymptotic running time of this code fragment for Horner’s rule?


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’s rule?


c. Prove that the following is a loop invariant for the while loop in lines 3 -5.

At the start of each iteration of the while loop of lines 3-5,

Interpret a summation with no terms as equaling 0. Your proof should follow the structure of the loop invariant proof presented in this chapter and should show that, at termination,


d. Conclude by arguing that the given code fragment correctly evaluates a polynomial characterized by the coefficients a0,a1,…, an.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 2.P