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- A. 1 5 0 10 2 16
- B. 0 5 1 8 2 16
- C. 1 7 0 10 2 16
- 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.
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? Integer g[4][4] = {{0,0,0,0}, {0,1,0,0}, {0,0,0,1}, {1,0,0,0}} // 1 = blocked Integer…
- What will be the output of the following pseudocode? (substring(s, i, len) is len characters starting at index i; a Set keeps one copy of…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division; strings are indexed from 0)…
- What will be the output of the following pseudocode? Function p(Integer n, Integer k) if (n == 0) return 1 end if if (n < 0 OR k == 0)…
- What will be the output of the following pseudocode? Integer calls = 0 Function f(Integer a, Integer b) calls = calls + 1 if (b == 0)…
- What will be the output of the following pseudocode? Integer g[5][5] = {{1,1,0,0,0}, {1,0,0,1,1}, {0,0,1,0,0}, {1,0,1,1,0}, {1,0,0,0,1}}…