One of the Applications of Divide and Conquer
Algorithmic Perspective
problem: multiplying two polynomials Given two polynomials , output their product . Represent a polynomial in the input or output as a vector of coefficients. In other words, output the coefficients of the product.
If has degree then has degree . Size of problem:
Naive algorithm:
Running time: coefficients to compute, each taking time.
Total: .
Lower-bound: for writing down all coefficients of c.
Can we get faster?
Idea 1
Representing a polynomial by giving a set of points e.g. representing a line via two points instead of the line equation. Possible because can recover the polynomial via the set of points, like computing line equation from two points 2 problems:
- How to quickly evaluate at these points?
- How to recover coefficients of C from the evaluations?
Takes d + 1 points to characterize a polynomial of d points.
Continuing on problem 1: Given a polynomial of degree , evaluate at distinct points.
Naive Approach
Each evaluation takes time. evaluations. Total time.
Fast Fourier Transform
Write A by separating even and odd powers of . and are polynomials of degree .
Need to evaluate at the set of squares of input points. What if we choose to come in positive/negative pairs? Can compute at points by evaluating points for both Recurrence would be:
But we cannot recurse: all points passed to are positive (squares); cannot divide into positive negative pairs. However, this is possible with complex numbers. After squaring them, they can still come in positive/negative pairs.
Solution: plot complex numbers in the X-Y plane (polar cords). After squaring,
Definition
The roots of unity are the numbers where
The set of roots of unity
- come in positive negative pairs
- Their squares are the roots of unity
roots of unity have exactly the properties of the special set of numbers With this set of n numbers, we can evaluate at the chosen points in time.
Evaluate coefficients into values and interpolate back to coefficient representations
Interpolation To get the final coefficients
Using the same FFT algorithm :3