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

How many lines, as a function of n (in (.)form), does the following program print? Write a recurrence and solve it. You may assume is a power of . function f (n) if n > 1:

print_line (‘‘still going’’)

f (n/2)

f (n/2)

Show that for any positive integers n and any base b , there must some power of b lying in the range [b,bn].

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

Question: You are given an infinite array A[·]in which the first n cells contain integers in sorted order and the rest of the cells are filled with . You are not given the value of n. Describe an algorithm that takes an integer x as input and finds a position in the array containing x, if such a position exists, in O(log n) time. (If you are disturbed by the fact that the array A has infinite length, assume instead that it is of length n, but that you don’t know this length, and that the implementation of the array data type in your programming language returns the error message whenever elements A[i]withi>n are accessed.)

A kway merge operation. Suppose you have ksorted arrays, each with nelements, and you want to combine them into a single sorted array ofkn elements.

(a)Here’s one strategy: Using the merge procedure from Section 2.3, merge the first two arrays, then merge in the third, then merge in the fourth, and so on. What is the time complexity of this algorithm, in terms of kand n?

(b) Give a more efficient solution to this problem, using divide-and-conquer.

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