ProgrammingHardAmazon OA · TCS Digital
What will be the output of the following pseudocode? (All variables are integers, so / is integer division)
What will be the output of the following pseudocode? (All variables are integers, so / is integer division)
Integer calls = 0
Procedure msort(Integer l, Integer r)
calls = calls + 1
if (l >= r)
return
end if
Integer m = (l + r) / 2
msort(l, m)
msort(m + 1, r)
// merge step (does not call msort)
End Procedure
msort(0, 5)
Print calls- A. 6
- B. 12
- C. 11
- D. 16
Correct answer: C. 11
The call tree splits 6 elements until single elements remain: it has 6 leaves (one per element) and 5 internal calls, so 2 × 6 − 1 = 11 calls in all.
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? (Arrays are indexed from 0) Integer a[5] = {1, 2, 3, 4, 5}, comps = 0 Procedure…
- What will be the output of the following pseudocode? (mod keeps the sign of the dividend; code/char convert between letters and codes)…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer x = 1221, rev = 0…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer fact[10], count = 0…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer n = 50, c = 0, p = 2…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer n = 36, s = 0 for…