Question: Provided code solve where says add code: package assignments2018.a2template; import java.math.BigInteger; public class Polynomial { private SLinkedList polynomial; public int size() { return polynomial.size(); }

Provided code solve where says add code: package assignments2018.a2template; import java.math.BigInteger; publicclass Polynomial { private SLinkedList polynomial; public int size() { return polynomial.size();Provided code solve where says add code:

package assignments2018.a2template;

import java.math.BigInteger;

public class Polynomial { private SLinkedList polynomial; public int size() { return polynomial.size(); } private Polynomial(SLinkedList p) { polynomial = p; } public Polynomial() { polynomial = new SLinkedList(); } // Returns a deep copy of the object. public Polynomial deepClone() { return new Polynomial(polynomial.deepClone()); } /* * TODO: Add new term to the polynomial. Also ensure the polynomial is * in decreasing order of exponent. */ public void addTerm(Term t) { } /**** ADD CODE HERE ****/ // Hint: Notice that the function SLinkedList.get(index) method is O(n), // so if this method were to call the get(index) // method n times then the method would be O(n^2). // Instead, use a Java enhanced for loop to iterate through // the terms of an SLinkedList. /* for (Term currentTerm: polynomial) { // The for loop iterates over each term in the polynomial!! // Example: System.out.println(currentTerm.getExponent()) should print the exponents of each term in the polynomial when it is not empty. } */ public Term getTerm(int index) { return polynomial.get(index); } //TODO: Add two polynomial without modifying either public static Polynomial add(Polynomial p1, Polynomial p2) { Polynomial p3= new Polynomial();

/**** ADD CODE HERE ****/ return null; } //TODO: multiply this polynomial by a given term. private void multiplyTerm(Term t) { /**** ADD CODE HERE ****/ } //TODO: multiply two polynomials public static Polynomial multiply(Polynomial p1, Polynomial p2) { /**** ADD CODE HERE ****/ return null; } //TODO: evaluate this polynomial. // Hint: The time complexity of eval() must be order O(m), // where m is the largest degree of the polynomial. Notice // that the function SLinkedList.get(index) method is O(m), // so if your eval() method were to call the get(index) // method m times then your eval method would be O(m^2). // Instead, use a Java enhanced for loop to iterate through // the terms of an SLinkedList.

public BigInteger eval(BigInteger x) { /**** ADD CODE HERE ****/ return new BigInteger("0"); } // Checks if this polynomial is same as the polynomial in the argument public boolean checkEqual(Polynomial p) { if (polynomial == null || p.polynomial == null || size() != p.size()) return false; int index = 0; for (Term term0 : polynomial) { Term term1 = p.getTerm(index); if (term0.getExponent() != term1.getExponent() || term0.getCoefficient().compareTo(term1.getCoefficient()) != 0 || term1 == term0) return false; index++; } return true; } // This method blindly adds a term to the end of LinkedList polynomial. // Avoid using this method in your implementation as it is only used for testing. public void addTermLast(Term t) { polynomial.addLast(t); } // This is used for testing multiplyTerm public void multiplyTermTest(Term t) { multiplyTerm(t); } @Override public String toString() { if (polynomial.size() == 0) return "0"; return polynomial.toString(); } }

4. Polynomial.eval (20 points) The polynomial object evaluates itself for a given value of x using Horner's method. The variable x is of BigInteger data type, as mentioned earlier. Horner's method greatly speeds up the evaluation for exponents with many terms. It does so by not having to re-compute the x fresh for each term. Note that you should not use Term.eval() method to evaluate a particular term. That method is provided for you only to help with testing, namely to ensure that your implementation of Horner's method is correct. 4. Polynomial.eval (20 points) The polynomial object evaluates itself for a given value of x using Horner's method. The variable x is of BigInteger data type, as mentioned earlier. Horner's method greatly speeds up the evaluation for exponents with many terms. It does so by not having to re-compute the x fresh for each term. Note that you should not use Term.eval() method to evaluate a particular term. That method is provided for you only to help with testing, namely to ensure that your implementation of Horner's method is correct

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!