retagged by
18,586 views
34 votes
34 votes

Consider the queues $Q_{1}$ containing four elements and $Q_{2}$ containing none (shown as the $\textsf{Initial State}$ in the figure). The only operations allowed on these two queues are $\textsf{Enqueue (Q, element)}$ and $\textsf{Dequeue (Q)}.$ The minimum number of $\textsf{Enqueue}$ operations on $Q_{1}$ required to place the elements of $Q_{1}$ in $Q_{2}$ in reverse order (shown as the $\textsf{Final State}$ in the figure) without using any additional storage is________________.

 

retagged by

6 Answers

0 votes
0 votes
Caption

1) Transfer all data from Q1 to Q2 so here no need to Enqueue on Q1

2) Now Q2 is like Q1 and then apply recursive algo on Q2 . No need to apply any operation on Q1 

So Ans is Zero .

0 votes
0 votes

“The minimum number of Enqueue operations on Q1 required to place the elements” 

E= Enqueue

D= Dequeue

Answer:

Related questions

41 votes
41 votes
3 answers
5