retagged by
8,225 views
10 votes
10 votes
Consider the following sequence of operations on an empty stack.$$\textsf{push}(54);\textsf{push}(52);\textsf{pop}();\textsf{push}(55);\textsf{push}(62);\textsf{s}=\textsf{pop}();$$Consider the following sequence of operations on an empty queue.$$\textsf{enqueue}(21);\textsf{enqueue}(24);\textsf{dequeue}();\textsf{enqueue}(28);\textsf{enqueue}(32);\textsf{q}=\textsf{dequeue}();$$ The value of $\textsf{s+q}$ is ___________.
retagged by

3 Answers

Best answer
14 votes
14 votes

Stack:

  • Push $54,$ push $52,$ pop (remove top element of stack)
  • Now stack $54$ (remove 52), push $55,$ push $62,$ pop
  • Now top element is $62$ (remove $62$ as $S$)
  • $S=62$

Queue

  • Enqueue $21,$ Enqueue $24$ dequeue (remove first element of queue)
  • Now queue $24$ (remove $21$), Enqueue $28,$ Enqueue $32,$ dequeue
  • Starting element is $24$ (remove $24$ as $Q$)
  • $Q = 24$

$S+Q = 62+24 = 86$

edited by
Answer:

Related questions

13 votes
13 votes
5 answers
1
Arjun asked Feb 18, 2021
8,019 views
In an undirected connected planar graph $G$, there are eight vertices and five faces. The number of edges in $G$ is _________.
33 votes
33 votes
4 answers
2
18 votes
18 votes
3 answers
3
Arjun asked Feb 18, 2021
11,515 views
A binary search tree $T$ contains $n$ distinct elements. What is the time complexity of picking an element in $T$ that is smaller than the maximum element in $T$?$\Theta(...