Data Structures and Algorithms in Java
Data Structures and Algorithms in Java
6th Edition
ISBN: 9781118771334
Author: Michael T. Goodrich
Publisher: WILEY
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
Consider a function f: N → N that represents the amount of work done by some algorithm as follow:   f(n) = {(1 if n is oddn if n is even)┤    Prove or disprove. f(n) is O(n).   Please show proof or disproof
Give regular expressions for the i (a) {w : w contains at most two 1s} (b) {w : w contains at least two 1s} (c) {w: every odd position in w is 1} (d) {w : w contains an even number of 0s, or
The order of growth of the function f(n)=2n×n is lower than the function g(n)= 2n×n2. Hence, f(n)=O(g(n)). Select one: a. None b. Yes c. No d. Maybe

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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education