Data Structures & AlgorithmsHardGATE CS · DSA

A recursive function is defined as f(0) = f(1) = 1 and f(n) = f(n−1) + 2·f(n−2) for n ≥ 2. Using memoization, what is f(6)?

  1. A. 21
  2. B. 37
  3. C. 43
  4. D. 44

Correct answer: C. 43

Building up the memo table from f(0) = f(1) = 1 using f(n) = f(n−1) + 2·f(n−2) step by step gives f(6) = 43. 21 is actually f(5), a common off-by-one when the table is read one step too early.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic