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
  1. A. 700 76 3
  2. B. 700 101 6
  3. C. 700 76 6
  4. 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.

More Pseudocode and Code Tracing questions

Exams that ask this topic