edited by
1,163 views
2 2 votes

Consider implementation of stack using queue by following algorithm.

Let $x$ be an element to be pushed in the stack

push(q1,x)
{
    EQ(q1,x)
    
    while(q1 does not contain 1 element) {
        k=DQ(q1)
        EQ(q1,k)
    }
    
}
pop(q1) {
    DQ(q1)
}

How many enqueue and dequeue operations required to push $2$ and pop $2$ elements in the empty stack?

2 Answers

0 0 votes
for 2 push-   2 en-queue

for 2 pop-     infinite en-queue and infinite de-queue
Position:
Show:

Related questions

9 9 votes
2 2 answers
361
361 views
GO Classes asked Jul 27
361 views
Given a stack $S$ with $5$ elements from top to bottom as:$2, 4, 6, 8, 10$and an empty queue $Q$.First, remove the elements one by one from $S$ and insert them into $Q$.T...
7 7 votes
1 1 answer
409
409 views
GO Classes asked Jul 27
409 views
Which of the following statements are true?$\text{S1.}$ Stack operations $\texttt{push}$, $\texttt{pop}$, and $\texttt{isEmpty}$ can be worst-case $O(1)$ for a linked-lis...
7 7 votes
3 3 answers
295
295 views
GO Classes asked Jul 8
295 views
A queue is implemented using two stacks $\text{S1}$ and $\text{S2}$.Use the implementation where $\texttt{dequeue()}$ is $\text{O(1)}$ by keeping the front of the queue a...
13 13 votes
4 4 answers
2.1k
2.1k views
gatecse asked Feb 23
2,076 views
Consider a stack $S$ and a queue $Q$. Both of them are initially empty and have the capacity to store ten elements each. The elements $1,2,3,4$, and $5$ arrive one by one...