§ FFT
- Evaluating a polynomial
p(x)
at [a0, a1, ... am]
in general is hard, even though we have the recurrence p(x) = po(x^2) + x pe(x^2)
. This makes the polynomials smaller (degree of po
, pe
is half of that of p
). However, we need to evaluate at all the points [a0...am]
, so to merge we need to merge values at [a0...am]
at each step. So our recurrence will be T(n) = T(n/2) + m
with T(1) = m
. This solves to O(nm)
. - The special property of DFT is that we can reconstruct
p(x)
at [w[n][0], ... wn[n][n-1]]
given the values of po
, pe
at [w[n/2][1], w[n/2][2], w[n/2][3], ... w[n/2][n/2-1]]
. So the number of points we need to evaluate the polynomial decreases with the size of the polynomial! - This makes the recurrence
T(n) = T(n/2) + n
with T(1) = 1
which is O(n log n)
.
§ Worked out example of FFT of 8 elements
p(x)≡a0x0+a1x1+a2x2+a3x3+a4x4+a5x5+a6x6+a7x7pe(x)≡a0x0+a2x+a4x2+a6x3po(x)≡a1+a3x+a5x2+a7x3P(x)=pe(x)=xpo(x)
Now suppose we know how to evaluate pe(x) and po(x) at [w40,w41,w42,w43]. where w4
is the 4th root of unity. We wish to evaluate p(x) at [w80,w81,w82,…,w87], where w8
is the 8th root of unity. The only two properties of the roots of unity we will need are:
- w82=w4.
- w84=−1.
Using the value of w8, the above two relations, the values po(w4k)=[po(1),po(w4,po(w42),po(w43)]
and pe(w4k)=[pe(1),pe(w4),pe(w42),pe(w43)], we evaluate p at powers of w8 ( [p(w8k)] ) as:
- p(w8k)=pe((w8k)2)+w8kpo((w8k)2)=pe(w4k)+w8kpo(w4k).
- p(w80)=pe((w80)+w80po(w80)=pe(1)+po(1)
- p(w81)=pe(w82)+w81po(w82)=pe(w41)+w8po(w41)
- p(w82)=pe(w84)+w82po(w84)=pe(w42)+w82po(w42)
- p(w83)=pe(w86)+w83po(w86)=pe(w43)+w83po(w43)
- p(w84)=pe(w88)+w84po(w88)=pe(w44)+w84po(w44)=pe(1)−po(1)
§ Solving the Recurrence: T(n) = n + T(n/2)
, with T(1) = 1
§ Proof 1:
Expand the recurrence:
= T(n)
= n + 2T(n/2)
= n + 2[n/2 + T(n/4)]
= n + n + 4T(n/4)
= n + n + 4[n/4 + 2T(n/8)]
= n + n + n + 8T(n/8)
= ...
= kn + ... 2^k T(n/2^k)
= (log n)n + 2^(log n) T(n/2^(log n))
= (log n)n + n T(n/n)
= (log n)n + n* 1
= (log n)n + n
§ Proof 2:
Consider the tree:
8
mrg:8
4 4
mrg:4 mrg:4
2 2 2 2
mrg:2 mrg:2 mrg:2 mrg:2
1 1 1 1 1 1 1 1
- Number of leaves is
n
. Cost of each leaf is T(1) = 1
. Total cost of leaf level is n
. - At each level above, total cost is
8 = 4*2 = 2*4
. - Number of levels in
log n
. - Total cost is cost of leaf
n
, plus cost of interior nodes n log n
.