ProgrammingHardTCS NQT · Accenture pattern
What is the final content of the queue (front to back, left to right) after this sequence of operations on an initially empty queue?
What is the final content of the queue (front to back, left to right) after this sequence of operations on an initially empty queue?
enqueue 87 enqueue 2 enqueue 71 enqueue 20 dequeue dequeue enqueue 57
- A. 87, 2, 57
- B. 71, 20, 57
- C. 71, 20
- D. 57, 20, 71
Correct answer: B. 71, 20, 57
A queue is FIFO: dequeue always removes the front (oldest) element. Tracing the sequence gives front-to-back [71, 20, 57]. Treating it like a stack (removing the most recent instead) gives the trap [87, 2, 57]; reading it back-to-front gives [57, 20, 71].
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? (Arrays are passed and assigned BY REFERENCE: b = a makes b point to the same array…
- What will be the output of the following pseudocode? (^ is bitwise XOR.) Integer x = 25, y = 31 x = x ^ y y = x ^ y x = x ^ y Print x, y
- What will be the output of the following pseudocode? (A square matrix's main diagonal is mat[i][i]; its anti-diagonal is mat[i][n-1-i]. If…
- This function uses a counter that PERSISTS across calls (a static/global variable), starting at 5. What does each of the 4 calls print, in…
- What will be the output of the following pseudocode? (A square matrix's main diagonal is mat[i][i]; its anti-diagonal is mat[i][n-1-i]. If…
- This function uses a counter that PERSISTS across calls (a static/global variable), starting at 2. What does each of the 4 calls print, in…