ProgrammingHardAccenture · TCS · Infosys
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 59 enqueue 43 enqueue 60 dequeue enqueue 11 enqueue 74 dequeue dequeue enqueue 57 enqueue 92
- A. 11, 74, 57
- B. 59, 43, 57, 92
- C. 92, 57, 74, 11
- D. 11, 74, 57, 92
Correct answer: D. 11, 74, 57, 92
A queue is FIFO: dequeue always removes the front (oldest) element. Tracing the sequence gives front-to-back [11, 74, 57, 92]. Treating it like a stack (removing the most recent instead) gives the trap [59, 43, 57, 92]; reading it back-to-front gives [92, 57, 74, 11].
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? (All variables are integers, so / is integer division. Array is sorted and indexed…
- What is the tightest time complexity of the following pseudocode, in terms of n? (Treat any constant like 2 as a fixed constant, not…
- 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 = 65, y = 72 x = x ^ y y = x ^ y x = x ^ y Print x, y
- This function uses a counter that PERSISTS across calls (a static/global variable), starting at 1. What does each of the 4 calls print, in…
- What will be the output of the following pseudocode? Function isEven(Integer n) if (n == 0) return true end if return isOdd(n - 1) end…