Exercise 11: Polynomial Addition

  • Download polynomial.java from here.
  • Your task is to implement the following method of the class Polynomial:
public static Map<Integer, Double> addition(List<Map<Integer, Double>> polynomials) {…}
  • The method expects a list of univariate polynomials (each of them stored in a map, as we discussed on the class) and it returns the sum of the given polynomials in the list.

A skeleton for the solution:

  • Create a new Map (let’s call sum) for the outcome polynomial,
  • Go through all the polynomials in the given list one by one (in a loop),
    • Go through all the power products in the current polynomial (in a nested loop),
      • add the value of the coefficient of the current power product to the corresponding element of the sum (whose key is equal to the key/power of the current power product),
  • return sum.
Last modified: Thursday, 15 May 2014, 11:47 AM