ProgrammingHardInfosys · Capgemini 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 90 dequeue enqueue 2 dequeue enqueue 89 enqueue 62 enqueue 79 dequeue dequeue enqueue 80
- A. 89, 80
- B. 79, 80
- C. 80, 79
- D. 79
Correct answer: B. 79, 80
A queue is FIFO: dequeue always removes the front (oldest) element. Tracing the sequence gives front-to-back [79, 80]. Treating it like a stack (removing the most recent instead) gives the trap [89, 80]; reading it back-to-front gives [80, 79].
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What is the tightest time complexity of the following pseudocode, in terms of n? (Treat any constant like 3 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 = 81, y = 10 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 4. 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…