ProgrammingHardCapgemini · Infosys 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 78 enqueue 13 dequeue enqueue 32 dequeue enqueue 45 enqueue 13
- A. 13, 45, 32
- B. 32, 45, 13
- C. 32, 45
- D. 78, 45, 13
Correct answer: B. 32, 45, 13
A queue is FIFO: dequeue always removes the front (oldest) element. Tracing the sequence gives front-to-back [32, 45, 13]. Treating it like a stack (removing the most recent instead) gives the trap [78, 45, 13]; reading it back-to-front gives [13, 45, 32].
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- Consider this naive recursive Fibonacci. How many TOTAL calls to fib (including the initial call) happen when computing fib(5)? Function…
- 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 = 90, y = 62 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…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division.) Function f(Integer n, Integer…
- What will be the output of the following pseudocode? (& is bitwise AND, >> is right shift.) Integer n = 3500, c = 0 while (n > 0) c = c +…