ProgrammingModerateTCS NQT · Accenture
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Procedure f(Integer n)
if (n == 0)
return
end if
Print n
f(n - 1)
Print n
End Procedure
f(4)- A. 4 3 2 1 4 3 2 1
- B. 4 3 2 1 1 2 3 4
- C. 1 2 3 4 4 3 2 1
- D. 4 3 2 1 0 1 2 3 4
Correct answer: B. 4 3 2 1 1 2 3 4
Each call prints n before and after the recursive call, so the numbers go down and then come back up: 4 3 2 1 1 2 3 4.
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? // a trie (prefix tree) starts with only an empty root for each word in {"car"…
- What will be the output of the following pseudocode? // LRU cache of capacity 2: get(k) returns the value or -1; put evicts the least…
- What will be the output of the following pseudocode? Integer g[3][4] = {{1, 1, 1, 0}, {1, 1, 1, 1}, {0, 1, 1, 1}} Integer c = 0 for (each…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Function count7(Integer n) if…
- What will be the output of the following pseudocode? String s = "ABCAB" Integer cnt[26] = all 0, total = 0 for (each ch in s) cnt[ch] =…
- What will be the output of the following pseudocode? String s = "COMPUTER" Integer i = 0, j = length(s) - 1 while (i < j) while (i < j AND…