ProgrammingHardTCS NQT · Infosys · Accenture

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer A[5] = {64, 25, 12, 22, 11}
repeat 2 times, with p = 0, then 1
    m = index of the smallest element in A[p..4]
    swap A[p] and A[m]
end repeat
Print A[0], A[1], A[2], A[3], A[4]
  1. A. 11 12 22 25 64
  2. B. 11 25 12 22 64
  3. C. 11 12 25 22 64
  4. D. 12 11 25 22 64

Correct answer: C. 11 12 25 22 64

Pass 1 swaps 64 and 11 giving 11 25 12 22 64; pass 2 swaps 25 and 12 giving 11 12 25 22 64.

More Pseudocode and Code Tracing questions

Exams that ask this topic