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- A. 25
- B. 13
- C. 15
- 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.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What will be the output of the following pseudocode? List L = [1, 2, 3, 4, 5, 6, 7] Integer idx = 0, k = 3 while (size(L) > 1) idx = (idx…
- What will be the output of the following pseudocode? Function gcd(Integer a, Integer b) while (b != 0) t = a mod b a = b b = t end while…
- What will be the output of the following pseudocode? String s = "{[()]}(()" Stack st Integer pops = 0, i Boolean ok = true for (i = 0; i <…
- What will be the output of the following pseudocode? Integer a[5] = {2, 5, 9, 14, 20}, i for (i = 1; i < 5; i = i + 1) a[i] = a[i] - a[i…
- What will be the output of the following pseudocode? Integer x = 0, i for (i = 1; i <= 10; i = i + 1) x = ((x << 1) ^ i) & 15 end for…
- What will be the output of the following pseudocode? Integer w[5][5], i, j for (i = 0; i < 5; i = i + 1) for (j = 0; j < 5; j = j + 1) if…