Stack MCQ Quiz - Objective Question with Answer for Stack - Download Free PDF

Last updated on May 11, 2025

Latest Stack MCQ Objective Questions

Stack Question 1:

The postfix equivalent of the infix expression (a + b)*(c*d - e) * f/g is :

  1. ab + cd*e - fg*/*
  2. ab cd*e - fg/** 
  3. ab cde* - fg/**
  4. abcd e*fg - /**

Answer (Detailed Solution Below)

Option 1 : ab + cd*e - fg*/*

Stack Question 1 Detailed Solution

The correct answer is ab + cd*e - fg*/*.

key-point-imageKey Points

  • To convert an infix expression to its postfix equivalent, follow the order of operations and use a stack to manage the operators.
  • The given infix expression is (a + b)*(c*d - e) * f/g.
    • First, evaluate the expression inside the parentheses: a + b and c*d - e.
    • The postfix notation for a + b is ab+.
    • The postfix notation for c*d - e is cd*e-.
    • Next, multiply the results of these two expressions: (ab+)(cd*e-).
    • The postfix notation for this multiplication is ab+cd*e-*.
    • Finally, multiply by f and divide by g: (ab+cd*e-)*f/g.
    • The postfix notation for this final expression is ab+cd*e-*f*g/.
  • Therefore, the postfix equivalent of the infix expression (a + b)*(c*d - e) * f/g is ab+cd*e-*f*g/.

additional-information-imageAdditional Information

  • Infix notation is the standard arithmetic and logical formula notation, where operators are placed between operands (e.g., a + b).
  • Postfix notation (also known as Reverse Polish Notation) places operators after their operands (e.g., ab+).
  • Postfix notation eliminates the need for parentheses to define operation order.
  • This method is particularly useful in computer science for evaluating expressions in a stack-based manner.

Stack Question 2:

Evaluate the following postfix expression and find the correct value in the following- 50, 60, +, 20, 10, -, *

  1. 1100
  2. 1000
  3. 9000
  4. 10

Answer (Detailed Solution Below)

Option 1 : 1100

Stack Question 2 Detailed Solution

The correct answer is 1100.

Key Points

  • To evaluate a postfix expression, follow these steps:
    • Read the expression from left to right.
    • Push operands onto a stack.
    • When an operator is encountered, pop the required number of operands from the stack, perform the operation, and push the result back onto the stack.
  • Let's evaluate the given postfix expression step-by-step: 50, 60, +, 20, 10, -, *
    • Push 50 onto the stack.
    • Push 60 onto the stack.
    • Encounter '+', pop 60 and 50, add them (50 + 60 = 110), push 110 onto the stack.
    • Push 20 onto the stack.
    • Push 10 onto the stack.
    • Encounter '-', pop 10 and 20, subtract them (20 - 10 = 10), push 10 onto the stack.
    • Encounter '*', pop 10 and 110, multiply them (110 * 10 = 1100), push 1100 onto the stack.
  • After processing all elements, the final value on the stack is 1100, which is the result of the postfix expression.

Additional Information

  • Postfix expressions, also known as Reverse Polish Notation (RPN), do not require parentheses to dictate operation precedence.
  • They are often used in computer science because they can be easily evaluated using a stack, which simplifies the parsing process.
  • Postfix notation is particularly useful in situations where the order of operations needs to be explicitly defined and consistently followed.
  • Commonly used in stack-based and expression evaluation algorithms in compilers and calculators.

Stack Question 3:

What will be the sequence of elements removed from the stack after performing the following operations

PUSH(10)

PUSH(20)

POP()

POP()

PUSH(30)

PUSH(40)

POP()

POP()

(A) 10

(B) 20

(C) 30

(D) 40

Choose the correct sequence from the options given below:

  1. (A), (B), (C), (D) 
  2. (B), (A), (D), (C) 
  3. (A), (B), (D), (C) 
  4. (B), (A), (C), (D)

Answer (Detailed Solution Below)

Option 2 : (B), (A), (D), (C) 

Stack Question 3 Detailed Solution

The correct answer is option 2.

Key Points

A stack is a LIFO (Last-In, First-Out) data structure. This means the last element pushed onto the stack is the first one to be popped off.

Given Operations:

  1. PUSH(10) → Stack: [10]
  2. PUSH(20) → Stack: [10, 20]
  3. POP() → Removes 20 → Stack: [10]
  4. POP() → Removes 10 → Stack: []
  5. PUSH(30) → Stack: [30]
  6. PUSH(40) → Stack: [30, 40]
  7. POP() → Removes 40 → Stack: [30]
  8. POP() → Removes 30 → Stack: []

Sequence of removed elements:

  1. 20
  2. 10
  3. 40
  4. 30

Corresponding to the options:

  • (A) 10
  • (B) 20
  • (C) 30
  • (D) 40

Sequence: (B), (A), (D), (C)

Hence, the correct answer is: option 2

Stack Question 4:

Stack works on the principle of _______.

  1. Mid Element First
  2. First In First Out
  3. Last In First Out
  4. Last In Last Out

Answer (Detailed Solution Below)

Option 3 : Last In First Out

Stack Question 4 Detailed Solution

The correct answer is Last In First Out.

key-point-imageKey Points

  • A stack is a data structure that works on the principle of Last In First Out (LIFO).
    • In this structure, the last element added to the stack is the first one to be removed.
    • This principle is analogous to a stack of plates: you add a plate to the top of the stack, and you also remove the topmost plate first.
    • Stacks are used in various applications, including function call management in programming, undo mechanisms in text editors, and parsing expressions in compilers.
    • Common operations associated with stacks are push (adding an element) and pop (removing an element).
    • Other stack operations include peek (viewing the top element without removing it) and isEmpty (checking if the stack is empty).

additional-information-imageAdditional Information

  • Stacks are implemented using arrays or linked lists.
  • They provide an efficient way to manage data, with a time complexity of O(1) for both push and pop operations.
  • Some common examples of stack usage in computer science include the evaluation of arithmetic expressions, reversing strings, and depth-first search algorithms.
  • The concept of stack is fundamental in computer science and is crucial for understanding other advanced data structures and algorithms.

Stack Question 5:

Evaluate the given postfix expression:

3 5 * 6 + 2 3 * -

  1. 39
  2. 15
  3. - 9 
  4. - 17

Answer (Detailed Solution Below)

Option 2 : 15

Stack Question 5 Detailed Solution

- khautorepair.com

The correct answer is 39.

Key Points

  • To evaluate the given postfix expression 3 5 * 6 + 2 3 * -, follow these steps:
    • Start with the expression: 3 5 * 6 + 2 3 * -
    • First, perform the multiplication: 3 * 5 = 15
    • The expression now becomes: 15 6 + 2 3 * -
    • Next, perform the addition: 15 + 6 = 21
    • The expression now becomes: 21 2 3 * -
    • Next, perform the multiplication: 2 * 3 = 6
    • The expression now becomes: 21 6 -
    • Finally, perform the subtraction: 21 - 6 = 15
    • Thus, the final result of the postfix expression 3 5 * 6 + 2 3 * - is 15.

Additional Information

  • Postfix notation, also known as Reverse Polish Notation (RPN), is a mathematical notation in which every operator follows all of its operands.
  • It is used because it can easily be evaluated using a stack data structure, which makes it very efficient for computer processing.
  • In postfix notation, there is no need for parentheses to define the order of operations as the position of the operators and operands dictates the order in which the operations are performed.
  • This method is widely used in calculators and computer algorithms for parsing arithmetic expressions.

Top Stack MCQ Objective Questions

What is the outcome of the prefix expression +, -, *, 3, 2, /, 8, 4, 1?

  1. 12
  2. 5
  3. 11
  4. 4

Answer (Detailed Solution Below)

Option 2 : 5

Stack Question 6 Detailed Solution

Download Solution PDF

The correct answer is option 2.

Concept:

Concept:

 

Method flow

Infix prefix postfix

Converse Infix

Converse Prefix Converse  Postfix
  1. Operand 1
  2. Operator
  3. Operand 2
  1. Operator
  2. Operand 1
  3. Operand 2
  1. Operand 1
  2. Operand 2
  3. Operator
  1. Operand 2
  2. Operator
  3. Operand 1
  1. Operator
  2. Operand 2
  3. Operand 1
  1. Operand 2
  2. Operand 1
  3. Operator

Prefix:

A Prefix expression prints the operator operand 1, and operand 2 respectively.

Explanation:

The given prefix is  +, -, *, 3, 2, /, 8, 4, 1.

F11 Madhuri Engineering 21.07.2022 D1Hence the correct answer is 5.

 

What is the postfix representation of the following infix expression?

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

  1. A B + C * D E * F - /
  2. A B * C + D E * F / -
  3. A B + C – D E * F / *
  4. A B + C * D E * F / -

Answer (Detailed Solution Below)

Option 4 : A B + C * D E * F / -

Stack Question 7 Detailed Solution

Download Solution PDF

Concept:

() has highest precedence

* and / has same precedence while + and – has same precedence

(* and /) and higher precedence than (+, -)

Associativity is left to right:

Explanation:

(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 / –

The result evaluating the postfix expression 10 5 + 60 6 / * 8 − is

  1. 284
  2. 213
  3. 142
  4. 71

Answer (Detailed Solution Below)

Option 3 : 142

Stack Question 8 Detailed Solution

Download Solution PDF

Calculation:

Postfix expression 10 5 + 60 6 / * 8 −

PUSH: 10 and 5(TOS)

10 5

Add: 10 + 5 = 15

PUSH: 15 60 6 (TOS)

15 60 6

Divide: 60/6 = 10

PUSH: 10

15 10

Multiply: 15 × 10 = 150

PUSH: 150 and 8

150 8

Subtract: 150 - 8 = 142

Diagram:

z,036

Evaluate Infix notation:

(((10 + 5) * (60 / 6)) - 8)  = ((15 * 10) - 8) = 150 - 8 = 142

In a stack, we can access the element-

  1. All of the options
  2. From any position 
  3. Which is entered at last 
  4. Which is entered at beginning

Answer (Detailed Solution Below)

Option 3 : Which is entered at last 

Stack Question 9 Detailed Solution

Download Solution PDF

The correct answer is Which is entered at last 

Key Points

  • Stack is LIFO type data structure. LIFO stands for Last-in-first-out.
  • Here, the element which is placed (inserted or added) last, is accessed first.
  • In stack terminology, insertion operation is called PUSH operation and removal operation is called POP operation.
  • We can see push(insertion) and POP(removal) both are occurring at top of stack.

 

In the given example we have inserted “6” in the last but removed “6” first. This is LIFO operation.

F1 Neha.B 02-02-21 Savita D 2

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:  

  1. P
  2. R
  3. Q
  4. S

Answer (Detailed Solution Below)

Option 4 : S

Stack Question 10 Detailed Solution

Download Solution PDF

Concept:

Stack:

Stack is a linear data structure that allows to insert or delete elements from one end i.e. from the top of the stack. It follows a particular order in which elements are inserted or deleted i.e. LIFO (Last in first out).

Queue:

Queue is a linear data structure in which elements are inserted from one end and deleted from the other ends. It follows FIFO property i.e. first in first out.

Explanation:

Given five items P, Q, R, S, and T.

These are pushed into the stack as : 

T (TOP)
S
R
Q
P

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:

Q R S T(FRONT)

Now, two items are deleted from the queue which is: T, S

These are inserted back into the stack.

Stack will be :

S (TOP)
T
P

Queue will be :

Q R

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

Consider the following postfix expression with single digit operands:

6 2 3 * / 4 2 * + 6 8 * -

The top two elements of the stack after second * is evaluated, are:

  1. 6, 3
  2. 8, 1
  3. 8, 2
  4. 6, 2

Answer (Detailed Solution Below)

Option 2 : 8, 1

Stack Question 11 Detailed Solution

Download Solution PDF

Postfix expression: 6 2 3 * / 4 2 * + 6 8 * -

F2 R.S. Nita 04.10.2019 D 10

F2 R.S. Nita 04.10.2019 D 11,ong

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

  1. stack
  2. priority queue
  3. graph
  4. cycles

Answer (Detailed Solution Below)

Option 1 : stack

Stack Question 12 Detailed Solution

Download Solution PDF

Concept:

  • A stack is an ordered list in which insertion and deletion are done at one end, called a top.
  • The last element inserted is the first one to be deleted. Hence, it is called the Last in First out (LIFO) or First in Last out (FILO) list.

Explanation:

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 

Additional Information

Number of moves required for n disc in a Tower of Hanoi is 2– 1 = 27 – 1 = 127. 

Stack underflow happens when one tries to pop (remove) an item from the stack when nothing is actually there to remove.

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?

  1. pos ← -1
  2. pos ← 0
  3. pos ← 1
  4. pos ← N - 1

Answer (Detailed Solution Below)

Option 4 : pos ← N - 1

Stack Question 13 Detailed Solution

Download Solution PDF

Concept:

Usually, the empty stack is initialized with value 0 and this value increments by 1 every time we push an element on to the stack.

The code for such a stack looks like this,

push (x)

                A[pos] ← x

                pos ← pos + 1 /the initial value is incremented by 1 as element is pushed onto the stack

end push

However, in the question, when push operation takes place, the value of variable is decremented by 1 (pos – 1).  Hence, initial value of pos will have to be N-1.

Explanation

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.

What would be the prefix notation for the given equation?

(a+(b/c) *(d^e)-f)

  1. -+fa*/bc^de
  2. -+a*b/c^def
  3. +-a*/^bcdef
  4. -+a*/bc^def

Answer (Detailed Solution Below)

Option 4 : -+a*/bc^def

Stack Question 14 Detailed Solution

Download Solution PDF

The correct answer is option 4.

Concept:

 

Method flow

Infix prefix postfix

Converse Infix

Converse Prefix Converse  Postfix
  1. Operand 1
  2. Operator
  3. Operand 2
  1. Operator
  2. Operand 1
  3. Operand 2
  1. Operand 1
  2. Operand 2
  3. Operator
  1. Operand 2
  2. Operator
  3. Operand 1
  1. Operator
  2. Operand 2
  3. Operand 1
  1. Operand 2
  2. Operand 1
  3. Operator

Infix:

An infix expression prints the operand 1, operator, and operand 2 respectively.

Postfix:

A Postfix expression prints the operand 1, operand 2, and operator respectively.

Prefix:

A Prefix expression prints the operator operand 1, and operand 2 respectively.

Converse postfix:

A converse postfix expression prints the operand 2, operand 1, and operator respectively.

Converse infix:

A converse infix expression prints the operand 2,  operator, and operand 1 respectively.

Converse prefix:

A converse prefix expression prints the operator, operand 2, and operand 1  respectively.

Explanation:

The given infix is, 

(a+(b/c) *(d^e)-f)

() is highest prority

The inner (b/c) is excutes first,

operand 1=b

operand 2=c

Operator= /

(a+/bc *(d^e)-f)

The inner (d^e) is excutes next,

operand 1=d

operand 2=e

Operator= ^

(a+/bc *^de-f)

The highest operator is * than +, -

operand 1=/bc

operand 2=^de

Operator= *

(a+*/bc^de-f)

The highest operator is + than -.

operand 1=

operand 2= */bc^de

Operator= +

(+a*/bc^de-f)

operand 1=+a*/bc^de

operand 2= f

Operator= There is no start phase in Virus Life Cycle.

The prefix is -+a*/bc^def.

Hence the correct answer is -+a*/bc^def.

A stack can be implemented using queue, but then we need to use atleast:

  1. 3 queues
  2. 2 queues
  3. only one queue is sufficient
  4. none of the options

Answer (Detailed Solution Below)

Option 2 : 2 queues

Stack Question 15 Detailed Solution

Download Solution PDF

A stack can be implemented using two queues. Let stack to be implemented be ‘x’ and queues used to implement be ‘a’ and ‘b’.

Method 1 (By push operation)
This method makes sure that the newly entered element is always at the front of ‘a’, so that pop operation just dequeues from ‘a’. ‘b’ is used to put every new element at front of ‘b’.

Method 2 (By making pop operation costly)
In a push operation, the new element is always enqueued to a. In pop() operation, if b is empty then all the elements except the last, are moved to b. Finally, the last element is dequeued from a and returned.

Therefore Option 2 is correct

Get Free Access Now
Hot Links: teen patti master game teen patti master online lucky teen patti teen patti royal - 3 patti