Loading...
Compute length-n DFT faster than naive O(n^2) summation: X[k] = sum a[j] * exp(-2*pi*i*j*k / n). Use parity split to form two size n/2 transforms.
Polynomial view: A(x) = Σ a_j x^j. Partition indices by parity:
Evaluate at roots of unity ω_n^k gives two n/2 transforms E[k], O[k] plus combination with twiddle factors:
Each level performs O(n) twiddle multiplies; height log2 n.
1function fft(a):2 n = length(a)3 if n == 1: return a4 even = fft(a[0::2])5 odd = fft(a[1::2])6 combine using roots of unity7 return result
T(n) = 2T(n/2) + O(n)
Master Theorem => O(n log n).
Bit-reversal: O(n). Butterfly stages: log2 n each with n/2 butterflies.