Courses
Courses for Kids
Free study material
Offline Centres
More
Store Icon
Store

Important Questions and Answers for Class 12 Computer Science Chapter 3 Stack | 2026-27

ffImage
banner

Class 12 Computer Science Chapter 3 Important Questions with Answers PDF Download

Class 12 Computer Science Chapter 3 Important Questions help students understand the Stack data structure through MCQs, short answers, Python programs and expression-based questions. The questions cover the LIFO principle, PUSH and POP operations, stack implementation using lists, infix-to-postfix conversion and postfix evaluation.


Practising these questions helps students understand how stacks work and apply them in Python programs. Students can also explore the Class 12 Computer Science Important Questions page for more chapter-wise revision resources.

Practice Class 12 Computer Science Chapter 3 Important Questions and Answers

A Stack is a linear data structure in which elements are inserted and removed from the same end, called the TOP. The following 15 questions include MCQs, very short answers, short answers and long answers. They cover stack operations, Python list methods, expression conversion and practical applications.


Class 12 Computer Science Chapter 3 Important Questions MCQ with Answers

Q1. What will be the output of the following Python program?

stack = [10, 20, 30]

stack.append(40)

print(stack.pop())

print(stack[-1])

(a) 30 followed by 40
(b) 40 followed by 30
(c) 40 followed by 20
(d) 30 followed by 20

Answer: (b) 40 followed by 30


Explanation: The append(40) method adds 40 to the top of the stack. The pop() method removes and returns 40. The last remaining element is 30.

Output:

40

30


Q2. What happens when the pop() method is called on an empty Python list?

(a) It returns zero.
(b) It returns None.
(c) It raises IndexError.
(d) It creates a new stack.

Answer: (c) It raises IndexError.


Explanation: Removing an element from an empty stack is called stack underflow. In Python, calling pop() on an empty list raises an IndexError unless the program first checks whether the stack is empty.


Q3. Which is the correct postfix expression for the infix expression A + B * C?

(a) A B + C *
(b) A B C * +
(c) + A * B C
(d) A * B + C

Answer: (b) A B C * +


Explanation: Multiplication has higher precedence than addition. Therefore, B * C is evaluated first, then A is added. In postfix notation, operators are placed after their operands.


Q4. What is the value of the postfix expression 7 8 2 * 4 / +?

(a) 9
(b) 11
(c) 15
(d) 20

Answer: (b) 11

Explanation:

  • 8 2 * gives 16.

  • 16 ÷ 4 / gives 4.

  • 7 4 + gives 11.


The final result is 11. The textbook's Example 3.2 evaluates the same expression using a stack.


Class 12 Computer Science Chapter 3 Very Short Answer Questions

Q5. What is a Stack in Python? Explain the LIFO principle with an example.

Answer: A Stack is a linear data structure where insertion and deletion occur at one end, called the TOP.


It follows the Last-In-First-Out (LIFO) principle, meaning the last element added is the first one removed.


Example:

stack = []

stack.append(10)

stack.append(20)

stack.append(30)


print(stack.pop())

Output:

30

Since 30 was added last, it is removed first.


Q6. Define PUSH, POP, overflow and underflow in a Stack.

Answer:

  • PUSH: Adds a new element to the top of the stack.

  • POP: Removes the topmost element from the stack.

  • Overflow: Occurs when you add an element to a stack that has reached its maximum capacity.

  • Underflow: Occurs when you try to remove an element from an empty stack.


In a Python list-based stack, the available capacity normally depends on memory rather than a fixed size. A programmer can also impose a maximum capacity.


Q7. Give any three practical applications of the Stack data structure.

Answer:

  1. Undo operations: A text editor can use a stack to reverse recent changes.

  2. Browser navigation: A stack can manage previously visited pages.

  3. Expression processing: Stacks help check balanced parentheses and evaluate arithmetic expressions.


Stacks are also useful for reversing strings and managing function calls.


Class 12 Computer Science Chapter 3 Short Answer Questions

Q8. Consider an empty stack S. Show the contents of the stack after each operation.

Perform the following operations:

PUSH(5)

PUSH(15)

PUSH(25)

POP()

PUSH(35)

POP()

Answer:


Step

Operation

Stack Contents (Bottom → Top)

1

PUSH(5)

[5]

2

PUSH(15)

[5, 15]

3

PUSH(25)

[5, 15, 25]

4

POP()

[5, 15]

5

PUSH(35)

[5, 15, 35]

6

POP()

[5, 15]


Final Stack: [5, 15]

Stack diagram after PUSH(35)


Stack diagram after PUSH(35)


The most recent element, 35, is at the TOP. After POP(), it is removed, and 15 becomes the new TOP.


Explanation: Stack elements are added and removed from the same end. Each POP() removes the most recently inserted element, following LIFO.


Q9. Differentiate between infix, prefix and postfix expressions with examples.

Answer:


Expression Type

Operator Position

Example

Infix

Between operands

A + B

Prefix (Polish)

Before operands

+ A B

Postfix (Reverse Polish)

After operands

A B +


For the expression (A + B) * C:


Notation

Expression

Infix

(A + B) * C

Prefix

* + A B C

Postfix

A B + C *


Explanation: Infix expressions use operator precedence and parentheses to indicate evaluation order. Prefix and postfix expressions arrange operators and operands so parentheses aren't needed for unambiguous evaluation.


Q10. Complete the following Python program to perform PUSH and POP operations on a stack.

stack = []


def PUSH(value):

    stack.__________(value)


def POP():

    if len(stack) == 0:

        print("Underflow")

    else:

        print(stack.__________())


PUSH(12)

PUSH(24)

POP()

Answer: The missing methods are append and pop.

Completed Program:

stack = []


def PUSH(value):

    stack.append(value)


def POP():

    if len(stack) == 0:

        print("Underflow")

    else:

        print(stack.pop())


PUSH(12)

PUSH(24)

POP()

Output:

24

Explanation: append() adds an element to the top. pop() removes and returns the most recently added element. The empty-stack check prevents a call to pop() when no elements remain.


Q11. Explain how a Stack is used to check balanced parentheses in an arithmetic expression.

Consider the expression:

((2+3)*(4/2))+2

Answer: A stack helps check whether each opening parenthesis has a corresponding closing parenthesis in the correct order.


Procedure:

  1. Push every opening parenthesis ( onto the stack.

  2. When a closing parenthesis ) is encountered, pop one opening parenthesis.

  3. If a closing parenthesis appears while the stack is empty, the expression is unbalanced.

  4. At the end, the stack must be empty for the parentheses to be balanced.


Step-by-Step Stack Status


Parenthesis Encountered

Action

Stack After Operation

(

PUSH

(

(

PUSH

((

)

POP

(

(

PUSH

((

)

POP

(

)

POP

Empty


Conclusion: The given expression has balanced parentheses because every opening parenthesis is matched, and the stack is empty at the end.


This illustrates how stacks are used to check expressions.


Class 12 Computer Science Chapter 3 Long Answer Questions

Q12. Write a Python program to reverse a string using a Stack. Explain how the LIFO principle is applied.

Answer: A stack can reverse a string because it removes the last inserted character first.


Program:

def reverse_string(text):

    stack = []


    for ch in text:

        stack.append(ch)


    reversed_text = ""


    while stack:

        reversed_text += stackpop()


    return reversed_text



word = "STACK"

print("Original String:", word)

print("Reversed String:", reverse_string(word))

Output:

Original String: STACK

Reversed String: KCATS


Explanation:

  1. An empty stack is created.

  2. Each character of STACK is pushed onto it.

  3. The last character, K, becomes the topmost element.

  4. pop() removes the characters one by one in reverse order.

  5. The removed characters form the reversed string, KCATS.


Stack Representation:


Stack Representation


Key Learning: The LIFO principle makes a stack useful for reversing sequences.


Q13. Convert the infix expression A + B - C * D into postfix notation using a Stack. Show each step.

Answer: During infix-to-postfix conversion, add operands directly to the postfix expression, and use a stack to manage operators.

Given Infix Expression:

A + B - C * D


Step-by-Step Conversion:

Symbol

Action

Operator Stack (Bottom → Top)

Postfix Expression

A

Add operand to output

Empty

A

+

PUSH operator

+

A

B

Add operand to output

+

AB

-

POP +, then PUSH -

-

AB+

C

Add operand to output

-

AB+C

*

PUSH higher-precedence operator

- , *

AB+C

D

Add operand to output

- , *

AB+CD

End

POP remaining operators

Empty

AB+CD*-


Final Postfix Expression:

A B + C D * -


Explanation:

  1. A and B are added to the output as operands.

  2. When - is encountered, the existing + is popped because both have equal precedence and addition/subtraction are left-associative.

  3. Multiplication has higher precedence than subtraction, so * is pushed above -.

  4. After processing all symbols, pop the remaining operators in order.

  5. The resulting postfix expression is A B + C D * -.


Key Learning: Operator precedence and associativity determine when operators must be removed from the stack.


Q14. Evaluate the following postfix expressions using a Stack. Show the stack status after each operation.

Given:

A = 3, B = 5, C = 1, D = 4

Evaluate:

(a) A B + C *
(b) A B * C / D *

Answer:

Part A: Evaluate A B + C *


Symbol

Action

Stack (Bottom → Top)

A

PUSH 3

[3]

B

PUSH 5

[3, 5]

+

POP 5 and 3; PUSH 8

[8]

C

PUSH 1

[8, 1]

*

POP 1 and 8; PUSH 8

[8]


Final Answer: 8

Part B: Evaluate A B * C / D *


Symbol

Action

Stack (Bottom → Top)

A

PUSH 3

[3]

B

PUSH 5

[3, 5]

*

Calculate 3 × 5

[15]

C

PUSH 1

[15, 1]

/

Calculate 15 ÷ 1

[15.0]

D

PUSH 4

[15.0, 4]

*

Calculate 15.0 × 4

[60.0]


Final Answer: 60 (or 60.0 when evaluated with Python's / operator).


Explanation: In postfix evaluation, operands are pushed onto the stack. When the evaluator encounters an operator, it pops two operands, performs the operation, and pushes the result back.


For subtraction and division, the order of the popped operands matters. The first value popped is the right operand, and the second is the left operand.


Q15. Write a Python program to create a Stack containing only odd numbers entered by the user. Display its contents and find the largest odd number.

Answer: The following program accepts numbers, stores only odd numbers in a stack and finds the largest odd number while popping the elements.


Program:

stack = []


n = int(input("How many numbers? "))


for i in range(n):

    num = int(input("Enter number: "))


    if num % 2 != 0:

        stack.append(num)


print("Odd Number Stack:", stack)


if len(stack) == 0:

    print("No odd numbers entered")

else:

    largest = stack[-1]


    print("Popping elements:")


    while len(stack) > 0:

        item = stack.pop()

        print(item)


        if item > largest:

            largest = item


    print("Largest Odd Number:", largest)

Sample Input:

How many numbers? 6

Enter number: 8

Enter number: 3

Enter number: 11

Enter number: 4

Enter number: 7

Enter number: 6

Output:

Odd Number Stack: [3, 11, 7]

Popping elements:

7

11

3

Largest Odd Number: 11


Explanation:

  1. An empty list represents the stack.

  2. The program accepts six integers.

  3. The program pushes only numbers that leave a remainder of 1 when divided by 2 onto the stack.

  4. The final stack contains [3, 11, 7].

  5. The elements are popped in reverse insertion order.

  6. Each popped number is compared with the current largest value.

  7. The largest odd number is displayed after the stack becomes empty.


Key Learning: This question combines Stack operations, loops, conditional statements and finding the maximum value.


How Do Stack Operations Help in Class 12 Computer Science Chapter 3?

A Stack helps organise data when you need to access the most recently added item first. It is useful in undo operations, browser history and arithmetic expression processing. Vedantu's Class 12 Computer Science Chapter 3 Important Questions help students practise these applications through Python programs and step-by-step stack problems.


Important Concepts

What Students Should Learn

LIFO Principle

Understand how the last inserted element is removed first.

PUSH and POP

Insert and remove elements from the TOP.

Stack Implementation

Use Python lists with append() and pop().

Infix and Postfix

Convert expressions using operator precedence.

Postfix Evaluation

Use a stack to calculate expression values.


How to Practise Class 12 Computer Science Chapter 3 Important Questions Effectively?

  • Trace stack operations: Draw the stack after every PUSH and POP.

  • Practise Python programs: Write functions to insert, remove and display stack elements.

  • Convert expressions: Solve infix-to-postfix questions step by step.

  • Evaluate postfix expressions: Track operands and intermediate results.

  • Check common errors: Identify underflow, operator-precedence mistakes, and incorrect operand order.


Regular practice helps students understand stack behaviour and solve Python programming and expression-based questions accurately.

Add links to all the tables.


Important Study Material Links for Class 12 Computer Science Chapter 3

Students can revise Stack concepts using these chapter-specific solutions and notes.


S. No

Important Study Material Links for Class 12 Computer Science Chapter 3

1

Class 12 Computer Science Chapter 3 Stack NCERT Solutions

2

Class 12 Computer Science Chapter 3 Stack Revision Notes


Class 12 Computer Science Chapter-Wise Important Questions

Explore Vedantu's Class 12 Computer Science chapter-wise important questions PDF resources for practice and focused revision.



Additional Study Materials for Class 12 Computer Science

FAQs on Important Questions and Answers for Class 12 Computer Science Chapter 3 Stack | 2026-27

1. Where can I download Class 12 Computer Science Chapter 3 Important Questions PDF?

Students can use Vedantu's Class 12 Computer Science Chapter 3 Important Questions PDF download option when the chapter PDF is published. It will help them revise Stack concepts, solved MCQs, PUSH and POP operations, Python programs and expression-based questions.

2. What is the difference between PUSH and POP operations in a Stack?

PUSH adds an element to the TOP of a stack, while POP removes and returns the topmost element. Both operations occur at the same end of the stack, following the Last-In, First-Out principle.

3. Why does a Stack follow the LIFO principle from Class 12 Computer Science Chapter 3?

A Stack allows insertion and deletion only at the TOP. Therefore, the last element inserted is the first one removed. For example, in a pile of plates, you generally remove the plate placed last first.

4. How can I solve Class 12 Computer Science Chapter 3 Important Questions MCQ accurately?

For stack-based MCQs, identify the starting stack and trace every PUSH and POP in order. For expression questions, check operator precedence and remember that postfix operators appear after their operands.

5. What is the difference between stack overflow and underflow in Class 12 Computer Science Chapter 3 Stack?

Overflow occurs when you push an element onto a stack that has reached its maximum capacity. Underflow occurs when you try to POP from an empty stack. In Python, calling pop() on an empty list raises an IndexError.

6. How is a Stack implemented using a Python list?

A Python list can represent a Stack. The append() method performs PUSH, and pop() performs POP. The last element of the list represents the TOP, so this implementation doesn't need a separate TOP variable.

7. Why is a Stack used to convert infix expressions into postfix expressions from Class 12 Computer Science Chapter 3?

A Stack temporarily stores operators and parentheses during conversion. Operators are removed based on precedence and associativity, producing the correct postfix expression without unnecessary parentheses.

8. What is the correct order of operands while evaluating postfix expressions?

When an operator is encountered, pop two operands from the Stack. The first popped value is the right operand, and the second is the left operand. This order is especially important for subtraction and division.

9. Can a Stack be used to reverse a string in Python?

Yes. Each character can be pushed onto a Stack and then popped to build the reversed string. Since the last character inserted is removed first, the resulting characters appear in reverse order.

10. How can I practise Stack questions beyond the textbook exercises?

After completing the textbook exercises, students can practise tracing Stack contents, writing Python PUSH and POP functions, checking balanced parentheses and evaluating postfix expressions. These activities help develop the programming and problem-solving skills needed for Chapter 3.

📌 Add Vedantu as a preferred source on Google