Assignment 3 - Divide-n-Conquer Algorithms in Python
This assignment is a part of the course "Data Structures and Algorithms in Python".
In this assignment, we will implement an efficient algorithm for polynomial multiplication.
project='python-divide-and-conquer-assignment'
Problem Statement - Polynomial Multiplication
Given two polynomials represented by two lists, write a function that efficiently multiplies given two polynomials. For example, the lists
[2, 0, 5, 7]
and[3, 4, 2]
represent the polynomials and .Their product is
i.e.
It can be represented by the list
[6, 8, 19, 41, 38, 14]
.
The Method
Here's the systematic strategy we'll apply for solving problems:
- State the problem clearly. Identify the input & output formats.
- Come up with some example inputs & outputs. Try to cover all edge cases.
- Come up with a correct solution for the problem. State it in plain English.
- Implement the solution and test it using example inputs. Fix bugs, if any.
- Analyze the algorithm's complexity and identify inefficiencies, if any.
- Apply the right technique to overcome the inefficiency. Repeat steps 3 to 6.
Let's apply this approach step-by-step.
Solution
1. State the problem clearly. Identify the input & output formats.
While this problem is stated clearly enough, it's always useful to try and express in your own words, in a way that makes it most clear for you.
Problem
Given two polynomial represented by two lists, we have to write a function that multiplies the given two polynomials.
Input
- poly1 - List representation of first polynomial.
- poly2 - List representation of second polynomial.
Output
- result - List representation of multiplied polynomial.
Based on the above, we can now create a signature of our function: