351 views
0 votes
0 votes

1 Answer

1 votes
1 votes
Pop operation means, we need to pop out the top element from the Stack.

If we store the same element in the queue that we have in stack, the top element of stack will be the last element in the Queue.

 

Suppose there are 2 Queues, Q1 and Q2.

 

Q1 has 'n' elements, now we have to perform pop operation. It means we need the last element from the Queue.

So, we'll dequeue every element except the last element from Q1 and enqueue in Q2.

This Step will Take

#Dequeue= n-1 step

#Enqueue= n-1 step

 

Now Dequeue from Q1(this will be the Pop operation), it'll take 1 step. Total number of Dequeue step is increased by 1.

#Dequeue= n-1 step + 1 step = n step

 

Now, we'll also have to restore the (n-1) element from Q1 to Q2,

So, we'll dequeue every element from Q2 and enqueue in Q1. As there are n-1 element so, n-1 dequeue and n-1 enqueue

 

Total #Dequeue= n step + n-1 step = 2n -1

Total #Enqueue= n-1 step + n-1 step = 2n - 2

Related questions

0 votes
0 votes
1 answer
1
0 votes
0 votes
1 answer
2
tishhaagrawal asked Dec 16, 2023
354 views
Below is my approach to solving this question, can anyone please explain if I am doing it the right way?Let X = #free slotssince, m =7 and n = 3So, $4 \leqslant x\leqsla...
0 votes
0 votes
1 answer
4
jugnu1337 asked Oct 22, 2023
352 views
Suppose A is a 12 by 9 incidence matrix from a connected (but unknown) graph with 9 nodes and 12 edges. The diagonal entries of $A^{T}.A$give the number of edges into eac...