Test: Stack - Computer Science Engineering (CSE) MCQ


Test Description

10 Questions MCQ Test Question Bank for GATE Computer Science Engineering - Test: Stack

Test: Stack for Computer Science Engineering (CSE) 2024 is part of Question Bank for GATE Computer Science Engineering preparation. The Test: Stack questions and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus.The Test: Stack MCQs are made for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Stack below.
Solutions of Test: Stack questions in English are available as part of our Question Bank for GATE Computer Science Engineering for Computer Science Engineering (CSE) & Test: Stack solutions in Hindi for Question Bank for GATE Computer Science Engineering course. Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free. Attempt Test: Stack | 10 questions in 30 minutes | Mock test for Computer Science Engineering (CSE) preparation | Free important questions MCQ to study Question Bank for GATE Computer Science Engineering for Computer Science Engineering (CSE) Exam | Download free PDF with solutions
*Answer can only contain numeric values
Test: Stack - Question 1

Let there be an infix string given below:
4 ↑ 2 ↑ 6 ∗ 3 + 5 − 6 ∗ 3 + 2 ∗ 4
Assume that the above infix string is being converted in to postfix string. How many maximum memory levels of operand stack will be required for this conversion?


Detailed Solution for Test: Stack - Question 1

Infix: This type of string is of the form a op b. Here the operator is between the pair of operands on which the operation is to be performed.
Postfix: This type of string is of the form a b op. Here the operator is placed after the pair of operands on whom the operation is to be performed.

  • To find the maximum levels of memory blocks required in operand stack for infix to postfix conversion can be found be finding the longest continuous operands in the postfix expression. As we can see, 426 is the longest sequence of operands in the final postfix expression, hence, 3 memory blocks will be required at most in the operand stack.
  • Similarly, maximum levels of memory blocks in operator stack is 2 as we can see in the table that only 2 operators at most are coming together.
Test: Stack - Question 2

Which of the following data structure to convert an Infix expression into equivalent Prefix/Postfix notation?

Detailed Solution for Test: Stack - Question 2

Conversion of infix to postfix is,​
Infix: ((a+b)*(c-d))




The postfix expression is ab+cd-*
Hence the correct answer is Stack.

1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: Stack - Question 3

The five items P,Q,R,S and T are pushed in a stack, one after the other starting from P. The stack is popped four times and each element is inserted in a queue. Then two elements are deleted from the queue and pushed back on the stack. now one item is popped from the stack. The popped item is:  

Detailed Solution for Test: Stack - Question 3

Given five items P, Q, R, S, and T.
These are pushed into the stack as : 

Now stack is popped four times, and each item popped is inserted into the queue.
So, items that are popped from the stack are: T, S, R, Q
After insertion into queue, queue looks like this:

Now, two items are deleted from the queue which is: T, S
These are inserted back into the stack.
Stack will be :

Queue will be :

Now, one item is popped from the stack which is S.

Test: Stack - Question 4

A stack is implemented with an array of ‘A [0..N – 1]’ and a variable ‘pos’. The push and pop operations are defined by the following code.

push(x)

                A[pos] ← x

                pos ← pos – 1

end push

pop( )

                pos ← pos + 1

                return A[pos]

end pop

Which of the following will initialize an empty stack with capacity N for the above implementation?

Detailed Solution for Test: Stack - Question 4

For example, if we take an array with N = 4 to represent our stack. It will be A [0, 1, 2, 3].
Now, in order to push four elements, say x, y, z, w

  • First we will push at x index 3 which is 4 – 1
  • Then, we will decrement pos and push y at index 2 and so on.

Note that, the pop operation is also behaving inversely here.

  • In usual stack, pop would decrement value of pos.

In our case, pop is incrementing the value of pos.

Test: Stack - Question 5

If the sequence of operations - push (1), push (2), pop, push (1), push (2), pop, pop, pop, push (2), pop are performed on a stack, the sequence of popped out values 

Detailed Solution for Test: Stack - Question 5

Initially stack is emput
Stack:
push(1)

push(2)

pop()

Output : 2
push(1)


push(2)

pop()

Output : 2 2
pop()

Output : 2 2 1
pop()

Output : 2 2 1 1
push(2)

pop()

Output : 2 2 1 1 2

Test: Stack - Question 6

A recursive problem like tower of hanoi can be rewritten without recursion using:

Detailed Solution for Test: Stack - Question 6

A recursive problem like the Tower of Hanoi can be rewritten using system stack or user-defined stack
Recurrence relation of tower of Hanoi:  T(n) = 2T(n - 1) + 1 

Test: Stack - Question 7

The queue data structure is to be realized by using stack. The number of stacks needed would be

Detailed Solution for Test: Stack - Question 7

Method 1 (efficient push):

  • push:
    • enqueue in queue1
  • pop:
    • while the size of queue1 is bigger than 1, pipe dequeued items from queue1 into queue2
    • dequeue and return the last item of queue1, then switch the names of queue1 and queue2

Method 2 (efficient pop):

  • push:
    • enqueue in queue2
    • enqueue all items of queue1 in queue2, then switch the names of queue1 and queue2
  • pop:
    • deqeue from queue1
*Answer can only contain numeric values
Test: Stack - Question 8

Consider the following pseudo-code to perform push and pop operation on a stack using enqueue(EQ) and dequeue(DQ) operations on 2 queues q1 and q2. Let x be an element to be pushed in the stack. answer the following questions.
push(q1,q2,x)
{
if(q1 is empty)
{
EQ(q2,x);
}
Else
{
EQ(q1,x);
}
}
pop(q1, q2)
{
if (q1 is empty)
{
if (q2 is empty) 

print “stack underflow”;
Exit;
}
else
{
while(q2 does not contain one element)
{
k= DQ(q2);
EQ(q1,k);
}
Return (DQ(q2));
}
}
Else
{
while(q1 does not contain one element)
{
k= DQ(q1);
EQ(q2,k);
}
Return (DQ(q1));
}
}
If we perform 8 push and 2 pop operations on the above algorithm then total how many enqueue and dequeue operations are performed on queues?


Detailed Solution for Test: Stack - Question 8

8 push operation is equivalent to 8 EQ operation.
2 pop operation is equivalent = 1st pop and 2nd pop one after the other
1st pop operation = (7 DQ(q1) + 7 EQ(q2) + 1 DQ(q1) )
2nd pop operation = (6 DQ(q2) + 6 EQ(q1) + 1 DQ(q2) )
Total =8EQ+ 15 DQ + 13 EQ = 36
Hence the correct answer is 36.

Test: Stack - Question 9

You are given two stacks with the element 1,2,3,4,5, which must be placed in the same sequence in both stacks. Once an element is added to a stack, it can only be popped and displayed (but it cannot be pushed onto the other stack again). So the possible actions are s.pop(), s.push(), and s.top() (to return the stack's top element), and the method display(int) outputs an integer result. Both stacks have access to these three operations. If it is not empty, you can do a pop operation whenever you want. Which of the following sequences cannot be produced with the aforementioned constraints?

Detailed Solution for Test: Stack - Question 9

Let S1 and S2 be two stacks and let pop(), push (), and top() be the operations on the stack.
The element 1,2,3,4,5 in order.
Option 1:
To obtain 3 1 2 4 5
S1.push(1) ;
S2.push(2);
S1.push(3);
display(S1.top());
S1.pop();
display(S1.top())
S1.pop();
display(S2.top())
S2.pop();
S1.push(4)
display(S1.top())
S1.pop();
S1.push(5);
display(S1.top())
S1.pop();

Option 2 : 4 1 5 2 3
There can be no way to generate option 2.

Option 3:
To generate  4 2 1 3 5
S1.push(1);
S1.push(2);
S2.push(3);
S2.push(4);
display(S2.top());
S2.pop();
display(S1.top());
S1.pop();
display(S1.top());
S1.pop();
display(S2.top());
S2.pop();
S1.push(5);
display(S1.top());
S1.pop();

Option 4:
To obtain option 5 4 3 2 1.
Push all elements onto the  stacks, The stack will be like:
1 2 3 4 5, where 5 is present at the top of the stack and 1 is at the bottom of the stack. Now popping those elements and printing will output the sequence 5 4 3 2 1.
Hence the correct answer is 4 1 5 2 3.

Test: Stack - Question 10

What is the postfix representation of the following infix expression?
(A + B) * C – D * E / F

Detailed Solution for Test: Stack - Question 10

(A + B) * C – D * E / F
A B + * C – D * E / F
A B + C * – D * E / F
A B + C * – D E * / F
A B + C * – D E * F /
A B + C * D E * F / –

63 videos|7 docs|165 tests
Information about Test: Stack Page
In this test you can find the Exam questions for Test: Stack solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Stack, EduRev gives you an ample number of Online tests for practice

Top Courses for Computer Science Engineering (CSE)

Download as PDF

Top Courses for Computer Science Engineering (CSE)