ProgrammingVery hardAmazon OA · Infosys SP

What will be the output of the following pseudocode? (Print writes its values on one line, separated by spaces)

What will be the output of the following pseudocode? (Print writes its values on one line, separated by spaces)
Integer burst[3] = {5, 3, 8}, left[3] = {5, 3, 8}
Integer time = 0, q = 2
Queue Q = {0, 1, 2}
while (Q not empty)
    Integer p = dequeue(Q)
    Integer run = min(q, left[p])
    time = time + run
    left[p] = left[p] - run
    if (left[p] > 0)
        enqueue(Q, p)
    else
        Print p, time
    end if
end while
  1. A. 1 5 0 10 2 16
  2. B. 0 5 1 8 2 16
  3. C. 1 7 0 10 2 16
  4. D. 1 9 0 12 2 16

Correct answer: D. 1 9 0 12 2 16

Round robin with quantum 2: P0 runs to 2, P1 to 4, P2 to 6, P0 to 8, P1 finishes at 9, P2 to 11, P0 finishes at 12, then P2 runs alone to 16. Output 1 9 0 12 2 16.

More Pseudocode and Code Tracing questions

Exams that ask this topic