What is the optimal adaptive grid for calculating a DFT using a fixed number of sampling points?
This can be split up in two questions for the sampling frequency and the window.

1) The required sampling frequency is given by the Nyquist theorem to be $f_s&gt;2*f_{max}$ with $f_{max}$ being the largest frequency in your signal. When sampling actual signals with an ADC there is usually a low pass filter to ensure an upper frequency limit.

2) The function $f(x)$ is usually defined to $-\infty&lt;x&lt;\infty$. However, you can only pass a finite portion to the DFT. The DFT is not a time-discrete Fourier Transform but a Fourier Series. Hence, it is defined on periodic signals.

If your signal is actually periodic then it is favorable to perform the DFT over whole periods. From the DFT's point of view, the signal you hand to it is repeated infinitely and when you pass it an incomplete period, there will be border effects resulting in frequencies showing up that are not in the original signal.

If your signal is time limited, all of it should be contained in the vector you pass to the DFT.

If the signal is neither time limited nor periodic you would theoretically need a DFT with infinite length, simular to the actual Fourier Transform which is defined for $-\infty&lt;x&lt;\infty$. Since this is not possible, Spectral Density Estimation techniques can be employed. The data can then be visualized with Spectogram plots showing the frequency content over time. It depends on what you are trying to achieve, really.