ProgrammingHardAmazon OA · Goldman Sachs OA
What will be the output of the following pseudocode? (Arrays are indexed from 0)
What will be the output of the following pseudocode? (Arrays are indexed from 0)
Integer a[8] = {170, 45, 75, 90, 802, 24, 2, 66}
List bucket[10] = all empty
for (each i from 0 to 7)
append a[i] to bucket[a[i] mod 10]
end for
Integer k = 0
for (each d from 0 to 9)
for (each x in bucket[d], in order)
a[k] = x
k = k + 1
end for
end for
Print a[2], a[3], a[5]- A. 2 802 75
- B. 802 2 45
- C. 90 802 24
- D. 802 2 24
Correct answer: B. 802 2 45
One pass of LSD radix sort groups by the units digit, keeping the original order inside each group: 170, 90 | 802, 2 | 24 | 45, 75 | 66. So a[2], a[3], a[5] = 802 2 45.
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? (All variables are integers, so / is integer division) Integer lo = 1, hi = 1000…
- What will be the output of the following pseudocode? (^ is bitwise XOR) Integer x = 0 for (each i from 1 to 10) x = x ^ i end for Integer…
- What will be the output of the following pseudocode? (^ is XOR, & is AND, >> is right shift) Integer x = 21, z = 22 Integer y = x ^ (x >>…
- What will be the output of the following pseudocode? (code(c) is the ASCII code: 'A' = 65, 'a' = 97) Function cmp(String a, String b)…
- What will be the output of the following pseudocode? Integer a[8] = {3, 1, 4, 1, 5, 9, 2, 6} Integer best = a[0], c = 1 for (each i from 1…
- What will be the output of the following pseudocode? Integer a[6] = {100, 4, 200, 1, 3, 2} Set s = all values of a Integer best = 0, len…