ProgrammingVery hardAccenture · Capgemini

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer calls = 0
Function F(Integer n)
    calls = calls + 1
    if (n < 2)
        return n
    end if
    return F(n - 1) + F(n - 2)
end function
F(6)
Print calls
  1. A. 25
  2. B. 13
  3. C. 15
  4. D. 21

Correct answer: A. 25

Calls satisfy C(n) = 1 + C(n-1) + C(n-2) with C(0) = C(1) = 1: 1, 1, 3, 5, 9, 15, 25. So C(6) = 25.

More Pseudocode and Code Tracing questions

Exams that ask this topic