# With Memoization Are Time Complexity & Space Complexity Always the Same?

I am studying Dynamic Programming using both iterative and recursive functions. With recursion, the trick of using Memoization the cache results will often dramatically improve the time complexity of the problem.

When evaluating the space complexity of the problem, I keep seeing that time O() = space O(). This is because we will have to cache all the results, but once we cache them it is O(1) to retrieve

Examples of this are

My question is, with Memoization, will the space & time complexity always be the same ? If not, why not ?

Edit - Clarification

This question is regarding the Space complexity of the recursive solution. I have solved the iterative solution using smaller space complexity before, i.e. keeping only a single row in the matrix. However for the recursive solution, I have never seen a recursive approach where items are deleted from the memoization table. I suppose you could combine recursion + iteration to only keep a single row in the memoization, but I have not seen an example where you start at the pure end, and only keep limited space.

• There are many examples for which this is not the case. What research have you done? – Raphael Jun 4 '16 at 15:20
• The first item in my answer applies to recursive implementations as well. – Raphael Jun 4 '16 at 16:26

• need $\omega(1)$ time to compute each table entry or
This is not a general rule. It is very possible for a dynamic programming algorithm to have greater time complexity than space complexity (but obviously not the other way around, since we spend at least $O(1)$ time per instance).
For instance, you mention that the dice sum problem can be solved in $O(D*T)$ time and space (if we let $D$ be the number of dice and $T$ be the target sum). It can also be solved in $O(D*T)$ time and $O(T)$ space, simply by noting that the computation of the values follows a specific pattern and that to compute the answer for $n$ dice, you only need the answers for $n$ and $n-1$ dice (and you can forget the answers for $n-2,n-3,\ldots$ dice).