Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following code fragment implements Homer's rule for evaluating a polynomial P(x) = simga_k=0^n a_k^x^k = a_0 + x(a_1 + x(a_2 +...+ x(a_n- + xa_n)...)),

image text in transcribed

The following code fragment implements Homer's rule for evaluating a polynomial P(x) = simga_k=0^n a_k^x^k = a_0 + x(a_1 + x(a_2 +...+ x(a_n- + xa_n)...)), given the coefficients a_0, a_1, ..., a_n and a value for x: y = 0 for i = n downto 0 y = a_i + x middot y a. In terms of -notation, what is the running time of this code fragment for Homer'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 Homer's rule? c. Consider the following loop invariant: At the start of each iteration of the for loop of lines 2-3, y = simga_k=0^n-(i+1) a_k+i+1x^k. Interpret a summation with no terms as equaling 0. Following the structure of the loop invariant proof presented in this chapter, use this loop invariant to show that, at termination, y = simga_k=0^n a_kx^k. d. Conclude by arguing that the given code fragment correctly evaluates a polynomial characterized by the coefficients a_0, a_1, ..., a_n. The following code fragment implements Homer's rule for evaluating a polynomial P(x) = simga_k=0^n a_k^x^k = a_0 + x(a_1 + x(a_2 +...+ x(a_n- + xa_n)...)), given the coefficients a_0, a_1, ..., a_n and a value for x: y = 0 for i = n downto 0 y = a_i + x middot y a. In terms of -notation, what is the running time of this code fragment for Homer'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 Homer's rule? c. Consider the following loop invariant: At the start of each iteration of the for loop of lines 2-3, y = simga_k=0^n-(i+1) a_k+i+1x^k. Interpret a summation with no terms as equaling 0. Following the structure of the loop invariant proof presented in this chapter, use this loop invariant to show that, at termination, y = simga_k=0^n a_kx^k. d. Conclude by arguing that the given code fragment correctly evaluates a polynomial characterized by the coefficients a_0, a_1, ..., a_n

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

Step: 3

blur-text-image

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

Murach's SQL Server 2012 For Developers

Authors: Bryan Syverson, Joel Murach, Mike Murach

1st Edition

1890774693, 9781890774691

Students also viewed these Databases questions