The best algorithm to solve a problem is that which requires less space in memory and takes less time to complete its execution. But in practice, it is not always possible to achieve both of these objectives.
There can be more than one algorithm to solve the same problem. One such algorithm may take more space but less time to complete its execution, whereas the other algorithm may take less space but more time to complete its execution. Therefore, we will have to sacrifice one at the cost of the other. Thus the choice of an algorithm involves a time-space tradeoff.