Question

i=n Consider the following procedure to evaluate a polynomial a;x at x = C. i = 0 procedure poly(ca ,...an power + 1 y cao f
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:)

First, power is set to 1

y is set to I = Op

for i from 1 to 2 (since n = 2)

i = 1

  • power is set to power * c = 1 * 2 = 2
  • y is set to y + a_1 * power = 1 + 1 * 2 = 1 + 2 = 3

i = 2

  • power is set to power * c = 2 * 2 = 4
  • y is set to y + a_2 * power = 3 + 3 * 4 = 3 + 12 = 15

i = 3, and thus exit the loop.

return y = 15.

Thus the algorithm returns the value of y = 15 at x = 2, which is what is required.

Add a comment
Know the answer?
Add Answer to:
i=n Consider the following procedure to evaluate a polynomial a;x' at x = C. i =...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ) Consider the following algorithm procedure polynomial (c, a0,a1, …, an)               power :=1               y≔a0...

    ) Consider the following algorithm procedure polynomial (c, a0,a1, …, an)               power :=1               y≔a0               for i=1 to n                              power≔power*c                              y≔y+ai*power               return y Find a big-O estimate for the number of additions and multiplications used by this algorithm.

  • Consider the following algorithm (known as Horner's rule) to evaluate f(x) = sigma_i=0^x a, x^i; poly...

    Consider the following algorithm (known as Horner's rule) to evaluate f(x) = sigma_i=0^x a, x^i; poly = 0; for(i=n; i>=0; i--) poly = x * poly + a_i a. Show how the steps are performed by this algorithm for x = 3, f(x) = 4x + 8x + x + 2. b. Explain why this algorithm works. c. What is the running time of this algorithm?

  • Consider the following algorithm Poly(A,a) --------------- 1. n = degree of polynomial (with coef A[n],..,A[0]) 2....

    Consider the following algorithm Poly(A,a) --------------- 1. n = degree of polynomial (with coef A[n],..,A[0]) 2. sum = 0 3. for i = n downto 0 4. sum = sum * a +A[i] show all steps!! (a) Determine the running time of the algorithm, your work should explain your answer (b) what is the loop invariant property of the loop in line 3.

  • f(x) = 2.10 Consider the following algorithm (known as Horner's rule) to evaluate -ax': poly =...

    f(x) = 2.10 Consider the following algorithm (known as Horner's rule) to evaluate -ax': poly = 0; for( i=n; i>=0; i--) poly = x * poly + ai a. Show how the steps are performed by this algorithm for x = 3, f(x) = 4x + 8x + x + 2. b. Explain why this algorithm works. c. What is the running time of this algorithm?

  • The polynomial addition C function of Program 2.6 padd is the code when the polynomial is used to...

    The polynomial addition C function of Program 2.6 padd is the code when the polynomial is used to arrange the polynomial in the two arrangement methods of the polynomial described in the text 2.4.2. For the remaining method, when the expression polynomial is arranged by a coefficient, create a polynomial addition C function padd() corresponding to Program 2.6. 66 Arrays And Structures are zero are not displayed. The term with exponent equal to zero does not shouw able since x...

  • NEED HELP IN C++, IT'S UGENT. I been trying to figure out for hours what is...

    NEED HELP IN C++, IT'S UGENT. I been trying to figure out for hours what is wrong with my code. I can not get the first derivative to display and its evaluation to display. my code is below: #include <iostream> #include <cmath> #include <iomanip> #include <string> #include <sstream> using namespace std; string polyToString(double poly[]) { stringstream ss; if (poly[0] == 0) { ss << poly[1]; }    if (poly[0] == 1) { int a = poly[1]; int b = poly[2];...

  • [10 marks] consider the following pseudocode: p := 0 x := 2fori:= 2ton p := (p...

    [10 marks] consider the following pseudocode: p := 0 x := 2fori:= 2ton p := (p + i ) * x a) How many addition(s) and multiplication(s) are performed by the above pseudocode?b) Express the time-complexity of the pseudocode using the big-Θ notation.) Trace the algorithm, below, then answer (c) and (d):   Procedure xyz(n: integer) s := 0, for i:= 1 to n, for j:= 1to i, s:= s+ j*(i− j+ 1) return s c) What is the time-complexity for...

  • The code should be written with python. Question 1: Computing Polynomials [35 marks A polynomial is...

    The code should be written with python. Question 1: Computing Polynomials [35 marks A polynomial is a mathematical expression that can be built using constants and variables by means of addition, multiplication and exponentiation to a non-negative integer power. While there can be complex polynomials with multiple variable, in this exercise we limit out scope to polynomials with a single variable. The variable of a polynomial can be substituted by any values and the mapping that is associated with the...

  • 3) [16 points totall Consider the following algorithm: int SillyCalc (int n) { int i; int Num, answer; if (n &lt...

    3) [16 points totall Consider the following algorithm: int SillyCalc (int n) { int i; int Num, answer; if (n < 4) 10; return n+ else f SillyCalc(Ln/4) answer Num Num 10 for (i-2; i<=n-1; i++) Num + = answer + answer; answer return answer } Do a worst case analysis of this algorithm, counting additions only (but not loop counter additions) as the basic operation counted, and assuming that n is a power of 2, i.e. that n- 2*...

  • I need help filling in the the code in the methods add, multiply, and evaluate package...

    I need help filling in the the code in the methods add, multiply, and evaluate package poly; import java.io.IOException; import java.util.Scanner; /** * This class implements evaluate, add and multiply for polynomials. * * * */ public class Polynomial {       /**    * Reads a polynomial from an input stream (file or keyboard). The storage format    * of the polynomial is:    * <pre>    * <coeff> <degree>    * <coeff> <degree>    * ...    *...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT