Answer: 0
We can reverse the elements of Q1 into Q2 using 0 Enqueue operations on Q1. This is achieved by systematically transferring elements from Q1 to Q2 and rotating Q2 using only its own Enqueue and Dequeue operations.
Let the initial state of Q1 be [1,2,3,4] (where 1 is at the front and 4 is at the rear) and Q2 be empty []. We want the final state of Q2 to be [4,3,2,1] (where 4 is at the front and 1 is at the rear).
The step-by-step process is as follows:
- Insert 1st element:
- Dequeue(Q1)→1, Enqueue(Q2,1). Now, Q2=[1].
- Insert 2nd element and rotate:
- Dequeue(Q1)→2, Enqueue(Q2,2). Now, Q2=[1,2].
- Dequeue(Q2)→1, Enqueue(Q2,1). Now, Q2=[2,1].
- Insert 3rd element and rotate:
- Dequeue(Q1)→3, Enqueue(Q2,3). Now, Q2=[2,1,3].
- Dequeue(Q2)→2, Enqueue(Q2,2). Now, Q2=[1,3,2].
- Dequeue(Q2)→1, Enqueue(Q2,1). Now, Q2=[3,2,1].
- Insert 4th element and rotate:
- Dequeue(Q1)→4, Enqueue(Q2,4). Now, Q2=[3,2,1,4].
- Dequeue(Q2)→3, Enqueue(Q2,3). Now, Q2=[2,1,4,3].
- Dequeue(Q2)→2, Enqueue(Q2,2). Now, Q2=[1,4,3,2].
- Dequeue(Q2)→1, Enqueue(Q2,1). Now, Q2=[4,3,2,1].
Throughout this entire process, we only performed Dequeue operations on Q1. No Enqueue operations were performed on Q1. Thus, the minimum number of Enqueue operations on Q1 is 0.