Recent questions tagged stack

9 9 votes
2 2 answers
404
404 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
469
469 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
1 1 answer
310
310 views
Assume there are $n$ elements in the data structure. Consider the following statements:$\text{S1}:$ A stack can be implemented using a linked list such that each individu...
0 0 votes
1 1 answer
139
139 views
A queue is to be implemented using two stacks and only a constant amount of extra memory. Which of the following correctly implements queue behavior with constant amortiz...
1 1 vote
2 2 answers
133
133 views
Consider the following Python code fragment:stack = [] while len(q) 0: stack.append(q.pop(0)) while len(stack) 0: q.append(stack.pop())Here, $\texttt{q.pop(0)}$ removes...
1 1 vote
2 2 answers
126
126 views
Consider the following stack-based Python code:stack = [] n = 50 while n 0: stack.append(n % 2) n = n // 2 while len(stack) 0: print(stack.pop(), end="")What is printed...
5 5 votes
2 2 answers
246
246 views
A stack is used to check whether parentheses, braces, and brackets are properly balanced.Consider the following two inputs:Input $1: \texttt{[()]\{\}\{[()()]()\}}$Input $...
6 6 votes
3 3 answers
321
321 views
Suppose an intermixed sequence of stack push and pop operations is performed. The push operations push the integers $0$ through $9$ in order. The pop operations print the...
7 7 votes
3 3 answers
286
286 views
A stack client reads tokens from left to right. If the token is a word, it is pushed onto the stack. If the token is $\texttt{-}$, one item is popped and printed.Consider...
7 7 votes
3 3 answers
320
320 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...
6 6 votes
2 2 answers
235
235 views
Which of the following statements is true about arithmetic expressions?Parentheses are needed in all arithmetic expressions. Infix expressions do not require precedence r...
5 5 votes
2 2 answers
214
214 views
Which of the following permutations can be obtained in the same order using a stack, assuming the input sequence is:$$5, 6, 7, 8, 9$$$7, 8, 9, 5, 6$ $5, 9, 6, 7, 8$ $7, 8...
4 4 votes
2 2 answers
215
215 views
If the following sequence of operations is performed on an initially empty stack:push(1), push(2), pop, push(1), push(2), pop, pop, pop, push(2), popwhat is the sequence ...
5 5 votes
3 3 answers
222
222 views
An initially empty stack undergoes the following operations:push(40) push(10) push(10) push(pop() + pop()) push(20) push(5) push(pop() / pop())Assume the division operati...
3 3 votes
1 1 answer
252
252 views
Arrange the following prefix expressions in ascending order on the basis of their values.$-\:*\: 2\: /\: 8\:4\:3$$\uparrow \:- \:* \: 3\:6\:*\: 4\:2\:5$$+\:-\:\uparrow \:...
13 13 votes
4 4 answers
2.2k
2.2k 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...
0 0 votes
2 2 answers
529
529 views
0 0 votes
1 1 answer
249
249 views
How can we implement a doubly linked list to build a stack and find the median? What would be the time complexity (insertion, deletion and median) ?
0 0 votes
1 1 answer
314
314 views
You were given an array of distinct elements of size n with indices starting from 0.-Every $(2i)^{th}$ element is pushed into a stack.-Every $(2i+1)^{th}$ element is enqu...
1 1 vote
0 0 answers
135
135 views
What is the output of the following java code?// Demonstrate block scope. class Scope { public static void main(String args[]) { int x=10; if (x =10) { int y =20; System....
4 4 votes
2 2 answers
695
695 views
Consider the following infix expression $Q:\left((A+B)^{*} D\right) \uparrow(E-F)$. The equivalent postfix expression of $Q$ is$A B+D ^{*} E F \uparrow$ -$A B+D^{*}-\upar...
1 1 vote
1 1 answer
277
277 views
The entire set of parameters, including return address that is stored for a procedure invocation is referred tostack framestack basestack limitstack record
2 2 votes
1 1 answer
363
363 views
Which of the following uses only increment operations for adding and removing element at either end?QueuesStacksPriority QueuesDeques
3 3 votes
2 2 answers
340
340 views
What is the result of evaluating the postfix expression "$43^{*} 25^{*}+b-$ " ?$8$$14$$10$$5$