ProgrammingVery hardAmazon OA · Goldman Sachs OA
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer table[7] = all -1, probes = 0, h
for each key in {50, 700, 76, 85, 92, 73, 101}
h = key mod 7
while (table[h] != -1)
h = (h + 1) mod 7
probes = probes + 1
end while
table[h] = key
end for
Print table[0], table[6], probes- A. 700 76 3
- B. 700 101 6
- C. 700 76 6
- D. 92 76 8
Correct answer: C. 700 76 6
Home slots: 50→1, 700→0, 76→6, 85→1 (taken, goes to 2), 92→1 (2 probes, to 3), 73→3 (to 4), 101→3 (2 probes, to 5). So table[0] = 700, table[6] = 76, and probes = 1 + 2 + 1 + 2 = 6.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What is the time complexity of the following pseudocode, as a function of n? for (i = 1; i < n; i = i 2) for (j = 0; j < i; j = j + 1)…
- What is the time complexity of the following pseudocode, as a function of n (n > 2)? while (n > 2) n = squareRoot(n) // integer square…
- What will be the output of the following pseudocode? Integer coins[3] = {1, 2, 5} Integer ways[0..6] = all 0 ways[0] = 1 for (each a from…
- What will be the output of the following pseudocode? (code(c) gives a letter's character code; strings are indexed from 0) String s =…
- What will be the output of the following pseudocode? // list: 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> NULL Node slow = head, fast = head while…
- What will be the output of the following pseudocode? Integer m[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} Integer j for (each d from 0 to…