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
2:21 m Ο 21% AlmaNet WE ARE HIRING Experienced Freshers Salesforce Platform Developer APPLY NOW SEND YOUR CV: Email: hr.almanet@gmail.com Contact: +91 6264643660 Visit: www.almanet.in Locations: India, USA, UK, Vietnam (Remote & Hybrid Options Available)
Provide a detailed explanation of the architecture on the diagram
hello please explain the architecture in the diagram below. thanks you

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