Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Suppose we want to evaluate the polynomial P(x) = a0 + a1x + a2x2 + ... + anxn at point x.

  1. Show that the following simple routine, known as Horner’s rule, does the job and leaves the answer in z.
    z = an
    for I = n-1 down to 0 :
    z = zx + ai
  2. How many additions and multiplications does this routine use, as a function of n ? Can you find a polynomial for which an alternative method is substantially better?

Short Answer

Expert verified
  1. The Horner’s rule, evaluates the polynomial and stores the answer in the z
  2. One multiplication and one addition per loop. The Horner’s rule is the optimal method to find the polynomial.

Step by step solution

01

Explain polynomial

A polynomial expression is the algebraic form of expression that has the degrees for the variables. The polynomial expression has the same variable with multiple degrees.

02

Show that the following simple routine, known as Horner’s rule, does the job and leaves the answer in z.

(a)

Consider the Horner’s ruleas follows,

z = an

for i = n - 1 down to 0 :

z = zx + ai

Let the loop invariant be 2 , when looping to i, then

zi=ai+ai+1x+ai+2x2+anxn-1, Then on the twenty first loop,

zi-1=zix+ai-1=ai-1+ai+1-1x+ai+2-1x2+...anxn-(i-1)=ai-1+aix+ai+1x2+...anxn-(i-1)

Therefore, it has been proved that the Horner’s rule compute the polynomials and store at z

03

How many additions and multiplications does this routine use and which alternative method is substantially better

(b)

Consider the Horner’s ruleas follows,

z = an

for i = n -1 down to 0 :

z = zx + ai

One multiplication and one addition per loop is performed, in total n multiplications and n additions are performed in the given scheme.

No alternative method calculates polynomial better than the Horner’s rule.

Therefore, One multiplication and one addition per loop. The Horner’s rule is the optimal method to find the polynomial.

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Question: Solve the following recurrence relations and give a bound for each of them.

(a)T(n)=2T(n/3)+1(b)T(n)=5T(n/4)+n(c)T(n)=7T(n/7)+n(d)T(n)=9T(n/3)+n2(e)T(n)=8T(n/2)+n3(f)T(n)=49T(n/25)+n(3/2)logn(g)T(n)=T(n-1)+2(h)T(n)=T(n-1)+nc,whereisaconstant(i)T(n)=T(n-1)+cn,whereissomeconstant(j)T(n)=2T(n-1)+1(k)T(n)=T(n)+1

You are given an array of nelements, and you notice that some of the elements are duplicates; that is, they appear more than once in the array. Show how to remove all duplicates from the array in time O(nlogn) .

Find the unique polynomial of degree 4 that takes on values p(1)=2,p(2)=1,p(3)=0,p(4)=4,andp(5)=0. Write your answer in the coefficient representation.

In Section 2.1 we described an algorithm that multiplies two n-bit binary integers x and y in time na, where a=log23. Call this procedure fast multiply (x,y).

(a) We want to convert the decimal integer 10n(a 1 followed by n zeros) into binary. Here is the algorithm (assume n is a power of 2):

function pwr2bin(n)

if n = 1: return10102

else:

z= ???

return fastmultiply(z,z)

Fill in the missing details. Then give a recurrence relation for the running time of the algorithm, and solve the recurrence.

(b) Next, we want to convert any decimal integer x with n digits (where n is a power of 2) into binary. The algorithm is the following:

function dec2bin(x)

if n=1: return binary [ x ]

else:

split x into two decimal numbers xt,xRwith n/2 digits each

return ???

Here binary [.] is a vector that contains the binary representation of all one-digit integers. That is, binary role="math" localid="1659333641173" [0]=02, binary [1]=12, up to binary [9]=10012. Assume that a lookup in binary takes 0(1) time. Fill in the missing details. Once again, give a recurrence for the running time of the algorithm, and solve it.

Question: Use the divide-and-conquer integer multiplication algorithm to multiply the two binary integers 10011011and10111010 and .

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free