Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
For each function, say whether a memory (a dictionary of answers) would help, and why.
factorial(n), for one value of n.fibonacci(n), the simple recursive version.power(base, exponent) called many times with the same two numbers.Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. A memory helps when the same smaller problem comes again and again, and the answer does not change.
Check. For each, ask two questions: does the same input come again? Does the same input always give the same answer?
Answer: no, yes, never, yes, yes.
Log in to join the discussion.
Loading…
With Standard, you also open 10 more problems, 2 Python labs and 1 extra course. Everything you have used here stays free, always.