Skip to content
GATEiit

GATE CSE 2022 Q62: Minimum enqueues on Q1 to reverse its elements into Q2

Question

Consider the queues Q1Q_1 containing four elements and Q2Q_2 containing none (shown as the Initial State in the figure). The only operations allowed on these two queues are Enqueue(Q,element) and Dequeue(Q). The minimum number of Enqueue operations on Q1Q_1 required to place the elements of Q1Q_1 in Q2Q_2 in reverse order (shown as the Final State in the figure) without using any additional storage is___________.

Initial state: Q1 holds 1, 2, 3, 4 from the head and Q2 is empty. Final state: Q1 is empty and Q2 holds 4, 3, 2, 1 from the head
Tap the figure to enlarge

Try it: numerical answer: type the value

Numerical answer. No negative marking.
Show answer and explanation

Answer: 0 (official GATE 2022 final answer key)

Concept used: Only enqueues on Q1Q_1 are counted; Q2Q_2 itself can be rotated (dequeue then enqueue into Q2Q_2) to place each new element at its front.

First step: Move 1 into Q2Q_2; move 2 in and rotate Q2Q_2 once so 2 is at the head; continue with 3 and 4.

Full step-by-step solution

Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.

Share this question

WhatsAppDownload image

Source: official GATE 2022 CS question paper and final answer key, organised by IIT Kharagpur. Question paper · Answer key