Skip to content

Fibonacci with a memory

planning ahead

Level 1 of 3

Also called Memoisation and Top-down dynamic programming.

fresh numbers

The test's questions that a run answers, asked again on new numbers whenever you like. The answer, its working and the reason for every other choice come from fibonacci with a memory's own run on the numbers shown.

choose one

question 1

How many calls does the method make on F(9)?

the answer, and why

the answer is C

2 times 9, less 1, which is 17. F(9) down to F(2) each ask for 2, which is 16, and the first call makes 17.

if you chose another

  • That is the plain method, with no memory.
  • That is how many numbers are worked out. 7 more calls are answered.
  • That is the most waiting at once.

new numbersthe test page's numbers

question 2

How many calls does the memo answer on F(8)?

the answer, and why

the answer is D

One for each of F(3) to F(8), the second ask of each, which is 6.

if you chose another

  • That is the most waiting at once.
  • That is all the calls, those worked out as well.
  • That is how many numbers are worked out.

new numbersthe test page's numbers

question 3

The method runs on F(7). What does the memo hold just after its second addition?

the answer, and why

the answer is C

F(2) is added first, as 1 + 0, and then F(3), as 1 + 1. Cells 0 to 3 hold 0, 1, 1 and 2.

if you chose another

  • That is after the first addition.
  • That is after the third, which adds F(4).
  • Read by cell, cell 0 holds 0. F(1) is written first, but it goes in cell 1.

new numbersthe test page's numbers