Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

Consider the polynomials with integer coefficients and positive integer exponents:

P(x) = a0 * x0 + a1 * x1 + ... + an-1 * xn-1

For programming purposes, a polynomial is represented as an array of integers. The array cell of index i corresponds to the polynomial coefficient ai, where i represents the exponent of the variable x.

For example, if the polynomial is P(x) = 2 * x3 - 9 * x2 + 0 * x1 + 8 * x0, its representation as an array of size 4 is shown below:

8 0 -9 2
0 2 2 3

Consider the problem of calculating the polynomial value for an integer value of its variable x.

As an example, for the above polynomial and for x = 2, the value of P(2) is -12.

a) Design and write the methods calculateBruteForce and calculateHorner for calculating the polynomial value for an integer value of x by using the brute force approach and respectively Horner's technique. Each method should take two parameters: the array of coefficients representing the polynomial and the value of x.

When implementing calculateBruteForce method, define and invoke your own method for raising x to a given power by using repetitive multiplications, instead of invoking a predefined method such as the Math.pow().

(a1) By analyzing the code, determine and indicate time complexity for each of the two methods in terms of Big-O notation.

(a2) Which of the two methods would perform better in terms of execution time? Explain.

b) Write a driver program PolyVal.java to validate the conclusions drawn from question a2). Consider a polynomial with 10 terms whose coefficients are stored in an integer array and are randomly generated in the interval -9 .. 9. Implement the following actions:

(b1) Generate and display the polynomial.

(b2) Generate and display a random integer value x in the interval 1 .. 9.

(b3) Invoke the two methods and display the polynomial value returned by each method for the x value generated at (b2).

(b4) Measure and display the execution time of the two methods as the arithmetic mean value of 1010 executions. Use the method System.nanoTime() for determining the execution time. Discuss the obtained results. Are the results in line with your answer to question a?

Note. Due to the behavior of the JVM and JIT compiler, the execution time of the repeated programs is much slower the first times they are run and therefore make sure to discard the measured values for the initial 10 runs.

Submission requirements

Submit the following before the due date listed in the Calendar:

1. The source file PolyVal.java.

The source code should use Java code conventions and professional code layout regarding white space management, indents and comments.

2. The Solution description document _HW1 (.pdf or .doc / .docx) containing:

(2.1) assumptions, main design decisions, error handling; (2.2) test cases and two relevant screenshots; (2.3) the answer and discussion required by questions a2) and b4); (2.4) lessons learned and (2.5) possible improvements. The size of the document file (including the screenshots) should be of two pages, single spaced, font size 10.

Java, Programming

  • Category:- Java
  • Reference No.:- M91789363
  • Price:- $70

Priced at Now at $70, Verified Solution

Have any Question?


Related Questions in Java

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Can someone kindly help me to consider whether java

Can someone kindly help me to consider whether Java provides the facility of operator overloading? If it does, may you kindly describe how overloading operators can be accomplished? If not, may you kindly describe why yo ...

Project requirementsfor the problem described in the next

Project requirements For the problem described in the next section, you must do the following: 1. include your student ID at the end of all filenames for all java code files. Three classes have been identified in section ...

Solving 2nd degree equationsbull write the following java

Solving 2nd degree equations • Write the following Java methods • boolean real-sols(double a, double b, double c): it returns true if the 2nd degree equation ax2 + bx + c has real solutions • double solution1(double a, d ...

Answer the following question whats the difference public

Answer the following Question : What's the difference public inheritance and private inheritance? What can derived classes inherit from base classes? What cannot be inherited from base classes?

In ruby the hash class inherits from enumerable suggesting

In Ruby, the Hash class inherits from Enumerable, suggesting to a programmer that Hashes are collections. In Java, however, the Map classes are not part of the JCF (Java Collections Framework). For each language, provide ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

Part a specification - robot simulationpart a

PART A Specification - Robot Simulation PART A Requirements To complete this assignment you will use the supplied eclipse project Robot P1/. It is already set up to execute a simple arm movement loop which you will build ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As