recursive w partial memoization and iterative versions