CameraIcon
CameraIcon
SearchIcon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

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

void insert(Q, x)
{
push(S1, x);
}
void delete (Q, x)
{
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 (mn) delete operations be performed in an arbitary order on an empty queue Q. Let x and y be the number of push and pop operations performed respectively in the processes. Which one of the following is true for all m and n?

A
n+m x2n and 2myn+m
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
B
2mx<2n and 2my2n
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
n+m x2n and 2my2n
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
2mx<2n and 2myn+m
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is A n+m x2n and 2myn+m
Number of push operations
= n(insert) + m (delete)
= n+ m

So, n+mx but there are maximum 2n insert operations

So, n+mx2n ...(1)

No. of pop operations = n + m

But there are 2m delete operations which are less than no. of pop operations, hence

2mn+m ...(2)

From (1) and (2):n+mx2n &
2mn+m

Form (1) and (2):n+mx2n &
2mn+m

flag
Suggest Corrections
thumbs-up
2
similar_icon
Similar questions
View More
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Permutations
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon