Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

static long power1(int x, int n){ //Power 1 long result = 1; ///Iterative for(int i = 1; i (10 pts) An array of doubles can

image text in transcribed

image text in transcribed

static long power1(int x, int n){ //Power 1 long result = 1; ///Iterative for(int i = 1; i (10 pts) An array of doubles can be used to represent a polynomial of one variable. The index of an item in the array represents the exponent, and the value of the array element is the coefficient of the term. For example, if the polynomial p(x) = 10x15 - 3.2x8 + x + 7.5 and is represented by an array p[], then p[15] = 10.0, p[8] = -3.2, p[1] = 1.0, p[0] = 7.5, and the other items in the array are zeroes. The degree of a polynomial is the exponent of its highest term. For example, the degree of p(x) above is 15. The method evaluate(x) can be implemented in several different ways. What is the execution time of each implementation described below in Big O notation? Also, justify each answer. a) Implementation 1: value = 0; for (int i = 0; i = 0; i--) // d is the degree of the polynomial value = value * x + p[i]; return value; d) Which one is the most efficient? a. Write an iterative method power to compute x" for n >0. b. Write a recursive method power2 to compute xu by using the following recursive formulation: X = 1 xn=x*xn if n-1 if n>0 c. Write a recursive method power3 to compute x" by using the following recursive formulation: x = 1 x" = (xn/2)2 if n>0 and n is even x"=x* (xn//2)2 if n>0 and n is odd

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_2

Step: 3

blur-text-image_3

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

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions

Question

=+With whom does the firm have to negotiate?

Answered: 1 week ago

Question

=+Are there shop stewards?

Answered: 1 week ago