recategorized by
3,174 views
2 votes
2 votes

____ number of queues are needed to implement a stack

  1. $1$
  2. $2$
  3. $3$
  4. $4$
recategorized by

3 Answers

1 votes
1 votes
Implementing stack by using two queues:
push(s,x)
1) Enqueue x to q1 (assuming size of q1 is unlimited). pop(s)
1) One by one dequeue everything except the last element from q1 and enqueue to q2.
2) Dequeue the last item of q1, the dequeued item is result, store it.
3) Swap the names of q1 and q2
4) Return the item stored in step 2.

Answer-B(2)
Answer:

Related questions

1 votes
1 votes
3 answers
1
Arjun asked Dec 7, 2018
1,257 views
The smallest element that can be found in time ____ in a binary max heap.$O(n \log n)$$O( \log n)$$O(n)$$O(n^2)$
5 votes
5 votes
5 answers
2
Arjun asked Dec 7, 2018
2,065 views
______ to evaluate an expression without any embedded function calls.Two stacks are requiredone stack is neededThree stacks are requiredMore than three stacks are require...
1 votes
1 votes
2 answers
3
Arjun asked Dec 7, 2018
3,415 views
For a given hash table $T$ with $10$ slots that stores $1000$ elements, the load factor $\alpha$ for $T$ is$100$$0.01$$200$$1.05$
1 votes
1 votes
1 answer
4
Arjun asked Dec 7, 2018
4,247 views
____ is the worst-case time complexity for all operations (i.e.,) search, update and delete) in a general Binary Search tree$O(n)$$O(n \log n)$$O( \log n)$ for search and...