http://nbviewer.jupyter.org/gist/leftaroundabout/83df89a7d3bdc24373ea470fb50be629
DFT, size 16
FFT, size 16
The difference in complexity is pretty evident from that, isn't it?
Here's how I understand FFT.
First off, I would always think about Fourier transforms foremostly as transforms of continuous functions, i.e. a bijective mapping $\operatorname{FT} : \mathcal{L}^2(\mathbb{R}) \to \mathcal{L}^2(\mathbb{R})$. In that light it's clear that it can't be really be necessary to go to the “deepest level” and loop over individual elements, because the “individual elements” are single points on the real line, of which there are over-countably infinite.
So how comes this transform is still well-defined? Well, it's crucial that it operates not on the general function space $\mathbb{R}\to\mathbb{C}$ but only on the space of (Lebesgue-, square-) integrable functions. Now, this integrability is not a very strong property (much weaker than differentiability etc.), but it does demand that the function becomes “locally discribable with countable information”. Such a discription is given by the coefficients of a short-time Fourier Transform.† The simplest case is that your function is continuous and you divide it in so small regions that it's basically constant in each of them. Then each of the STFTs has most strongly a zeroth term. If you ignore the (anyways decaying) other coefficients then each domain is just a single data point. Of all these short-time–LF-limit coefficients, you could take a discrete Fourier transform. In fact, that's exactly what you do when performing any FT on measured real-world data!
The measured data needn't necessarily correspond to a fundamental physical quantity, though. For instance, when you measure some light intensity, you're really just measuring the amplitude of an electromagnetic wave whose frequency is itself too high to be sampled with an ADC. But clearly you can also compute the DFT of a sampled light-intensity signal, and cheaply so, despite the insane frequency of the light-wave.
This could be understood as the most important reason FFT is cheap:
Don't bother trying to see the individual oscillation cycles from the highest level. Instead, transform only somewhat high-level information that's already been preprocessed locally.
That's not all there is to it, though. The great thing about FFT is that is still gives you all the information a complete DFT would give. I.e. all the information you'd also get when sampling the exact electromagnetic wave of a light-beam. Can this be accomplished by transforming a photodiode signal? – can you measure the exact light-frequency from that?
Well, the answer is no you can't. That is, unless you apply extra tricks.
First of all, you need to at least roughly measure the frequency in the short time blocks. Well, that's possible with a spectrograph. But it's only possible up to a precision of $\Delta \nu = 1/{\Delta t}$, a typical uncertainty relation‡.
By having overall a longer time span, we should also be able to narrow down the frequency uncertainty. And this is indeed possible, if you measure locally not just the rough-frequency but also the phase of the wave. You know that a 1000 Hz signal will have exactly the same phase if you look at it one second later. Whereas a 1000.5 Hz signal, while being indistinguishable on the short-scale, will have inverted phase one second later.
Luckily, that phase information can very well be stored in a single complex number. And that's how FFT works! It starts out with lots of small, local transformations. These are cheap – for one thing obviously because they only use a small amount of data, but secondly because they know that, due to the short time span, they can't resolve the frequency very precisely anyway – so it's still affordable even though you do a whole lot of such transformations.
These do, however, record also the phase, and from that you can then make the frequency resolution more exact on the top-level. The required transformation is again cheap, because it doesn't itself bother with any high-frequency oscillations but only with the pre-processed low-frequency data.
†Yup, my argumentation is a bit circular at this point. Let's just call it recursive and we're fine...
‡This relation is not quantum mechanical, but the Heisenberg uncertainty has actually the same fundamental reason.
sudo
in your code example could be confusing, as that is a well known command in the computer world. You probably meant psuedocode. $\endgroup$