Data Structures & AlgorithmsHardHCLTech · Wipro pattern

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(10)?

  1. A. 341
  2. B. 265
  3. C. 683
  4. D. 684

Correct answer: C. 683

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(10) = 683. 341 is actually f(9), 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