ProgrammingModerateTCS NQT · Infosys
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer t[0..10]
t[0] = 0
t[1] = 1
t[2] = 1
for (each i from 3 to 10)
t[i] = t[i - 1] + t[i - 2] + t[i - 3]
end for
Print t[7], t[10]- A. 44 274
- B. 13 149
- C. 24 81
- D. 24 149
Correct answer: D. 24 149
The tribonacci numbers run 0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149: t[7] = 24 and t[10] = 149.
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? (strings are indexed from 0) String s = "{[()]}([)]" Stack st = empty Integer bad =…
- What will be the output of the following pseudocode? Queue q = {1, 2, 3, 4, 5} Integer k = 3 Stack st = empty for (each i from 1 to k)…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) // numbers stored as digit…
- What will be the output of the following pseudocode? // circular list of 6 people: 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> back to 1 Node p = node 1…
- What is the time complexity of the following pseudocode, as a function of n? Function f(Integer n) if (n <= 1) return 1 end if return f(n…
- What is the time complexity of the following pseudocode, as a function of n? Procedure g(Integer n) if (n <= 1) return for (each i from 1…