• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Data Structures | Queue | Question 11

An implementation of a queue Q, using two stacks S1 and S2, is given below: 

C
void insert(Q, x) {
   push (S1, x);
}
 
void delete(Q){
   if(stack-empty(S2)) then 
      if(stack-empty(S1)) then {
          print(Q is empty);
          return;
      }
      else while (!(stack-empty(S1))){
          x=pop(S1);
          push(S2,x);
      }
   x=pop(S2);
}

Let n insert and m (<=n) delete operations be performed in an arbitrary order on an empty queue Q. Let x and y be the number of push and pop operations performed respectively in the process. Which one of the following is true for all m and n?

(A)

n+m <= x < 2n and 2m <= y <= n+m

(B)

n+m <= x < 2n and 2m<= y <= 2n

(C)

2m <= x < 2n and 2m <= y <= n+m

(D)

2m <= x <2n and 2m <= y <= 2n

Answer

Please comment below if you find anything wrong in the above post
Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!

Last Updated :
Share your thoughts in the comments