Data Structures and Algorithms in Java
Data Structures and Algorithms in Java
6th Edition
ISBN: 9781119278023
Author: Michael T. Goodrich; Roberto Tamassia; Michael H. Goldwasser
Publisher: Wiley Global Education US
bartleby

Concept explainers

Expert Solution & Answer
Book Icon
Chapter 4, Problem 54C

Explanation of Solution

a.

Simple method to compute p(x):

Let us consider the “p(x)” polynomial of degree “n”.

The method to compute the polynomial of degree is given below:

//Define the simplePolynomial() method

public static double simplePolynomial(double a[], double n)

{

  //Declare the variable

double sum = 0;

  //Loop executes until the length of array

for(int i=0; i<a.length; i++)

  //Compute the polynomial of degree

  sum = sum + a[i] * Math.pow(n, a.length - i - 1);

//Return the polynomial of degree

return sum;

}

Running time:

In the above code, the computation of polynomial of degree is given below:

  • For each and every array term,
    • a[0] is “0” operation.
    • a[1]× x is “1” operation.
    • a[2]× x × x is “2” operations.
    • a[3]× x × x × x is “3” operations

Explanation of Solution

b.

Method to compute p(x) in O(n(logn)) time:

Let us consider the “p(x)” polynomial of degree “n”.

The method to compute the polynomial of degree is given below:

//Define the Polynomial() method

public static double Polynomial(double a[], double n)

{

  //Declare the variable

double sum = 0;

  int i=0;

  //Loop executes until the length of array

while(i<a.length)

{

  //Compute the polynomial of degree

  sum = sum + a[i] * Math.pow(n, a.length - i - 1);

  //Increment "i" by "1"

  i = i++;

  }

//Return the polynomial of degree

return sum;

}

Running time:

In the above code, the computation of polynomial of degree is given below:

  • For each and every array term,
    • a[0] is “0” operation.
    • a[1]× x is “1” operation

Explanation of Solution

c.

Horner method to compute p(x):

Let us consider the “p(x)” polynomial of degree “n”.

The method to compute the polynomial of degree is given below:

//Define the HornerPolynomial() method

public static double HornerPolynomial(double a[],double n)

{

  //Declare the variable

double sum = 0;

  //Loop executes until the length of array

for(int i=1;i< a

Blurred answer
Students have asked these similar questions
need help with thi Next, you are going to combine everything you've learned about HTML and CSS to make a static site portfolio piece. The page should first introduce yourself. The content is up to you, but should include a variety of HTML elements, not just text. This should be followed by an online (HTML-ified) version of your CV (Resume). The following is a minimum list of requirements you should have across all your content: Both pages should start with a CSS reset (imported into your CSS, not included in your HTML) Semantic use of HTML5 sectioning elements for page structure A variety other semantic HTML elements Meaningful use of Grid, Flexbox and the Box Model as appropriate for different layout components A table An image Good use of CSS Custom Properties (variables) Non-trivial use of CSS animation Use of pseudeo elements An accessible colour palette Use of media queries The focus of this course is development, not design. However, being able to replicate a provided design…
Using the notation

you can select multipy options

Chapter 4 Solutions

Data Structures and Algorithms in Java

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
Text book image
Operations Research : Applications and Algorithms
Computer Science
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Brooks Cole
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT