recursion and memoizaation