An iterative algorithm which just counts the number of steps until reaching 1 is trivial. The problem is to also update the cache for all the intermediate values.
In this particular case there is an iterative algorithm which doesn't require an explicit stack. It uses two passes: the first counts the total number of steps, and the second updates the cache.
def next(n):
if n % 2 != 0:
return 3*n + 1
else:
return n/2
def collatz(n):
count = 0
i = n
while i not in table:
count += 1
i = next(i)
count += table[i]
i = n
while i not in table:
table[i] = count
count -= 1
i = next(i)
return table[n]