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
Please original work In the progression from raw data to actionable knowledge, business analysts play a crucial role in transforming and interpreting data to support strategic decision-making. What do you think are the most important skills a business analyst needs to effectively navigate the transition from data to information and then to knowledge?  How can organizations ensure that analysts are equipped to extract meaningful insights that drive informed decisions? Share examples or insights from your own experiences or studies. Please cite in text references and add weblinks
Research enterprise network services commonly performed by Linux servers. Choose 3 and describe their function, as well as why they are typically set up on Linux machines.
The term color tone refers to the "temperature" of a photo.​ Question 17Select one: True False

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