Added algorithm based optimization using fft.