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

Class 12 Computer Science Chapter 3: Stack – NCERT Solutions & Key Answers

ffImage
banner

Stepwise NCERT Solutions for Stack Chapter – Class 12 Computer Science

Stuck with NCERT Solutions for Class 12 Computer Science Chapter 3 Stack? This page is your one-stop guide for stepwise, exam-ready answers, explained simply for 2025–26 CBSE preparation. Focus on understanding each Stack operation, not just memorizing them, for a smarter score boost.


Find detailed exercise-wise solutions, handy Stack definitions, and sample diagrams—all mapped to the CBSE marking scheme. Whether you want quick revision or full explanations, use our free PDF to practice push/pop operations and ace Stack questions in exams.


Get important exam tips, avoid common mistakes, and learn how to structure answers for scoring full marks. With these curated Class 12 Stack solutions, you’re all set for confidence and clarity—right when it counts most.


Stepwise NCERT Solutions for Stack Chapter – Class 12 Computer Science

1. State TRUE or FALSE:

(a) Stack is a linear data structure

(b) Stack does not follow LIFO rule

(c) PUSH operation may result into underflow condition

(d) In POSTFIX notation for expression, operators are placed after operands

Answer:
(a) True

(b) False

(c) False

(d) True


2. Find the output of the following code:


(a)

result = 0
numberList = [10, 20, 30]
numberList.append(40)
result = result + numberList.pop()
result = result + numberList.pop()
print("Result =", result)

Answer: Result = 70


(b)

answer = []
output = ''
answer.append('T')
answer.append('A')
answer.append('M')
ch = answer.pop()
output = output + ch
ch = answer.pop()
output = output + ch
ch = answer.pop()
output = output + ch
print("Result =", output)

Answer: Result = MAT


3. Write a program to reverse a string using stack.


Answer:

def push(stack, item):
    stack.append(item)
def pop(stack):
    if stack == []:
        return
    return stack.pop()
def reverse(string):
    n = len(string)
    stack = []
    for i in range(n):
        push(stack, string[i])
    string = ""
    for i in range(n):
        string += pop(stack)
    return string
string = input("Enter a string: ")
print("String:", string)
reversedStr = reverse(string)
print("Reversed String:", reversedStr)

4. For the arithmetic expression: ((2+3)*(4/2))+2 show the parentheses-matching process step by step using a stack.


Answer:

  • Scan from left to right. For each opening parenthesis '(', push onto the stack. For each closing parenthesis ')', pop from the stack.
  • If stack is empty after entire scan and every ')' matched an '(', then the parentheses are balanced.


5. Evaluate the following postfix expressions (given A=3, B=5, C=1, D=4; show stack after each step):

(a) A B + C *

Answer:

A = 3, B = 5, C = 1

  • Step-by-step:
    Push 3 → [3]
    Push 5 → [3,5]
    Pop 5, 3, add → 8
    Push 8 → [8]
    Push 1 → [8,1]
    Pop 1, 8, multiply → 8
    Final Stack: [8], Answer = 8

(b) A B * C / D *

Answer:

A = 3, B = 5, C = 1, D = 4
  • Step-by-step:
    Push 3 → [3]
    Push 5 → [3,5]
    Pop 5, 3, multiply → 15
    Push 15 → [15]
    Push 1 → [15,1]
    Pop 1, 15, divide → 15/1 = 15
    Push 15 → [15]
    Push 4 → [15,4]
    Pop 4, 15, multiply → 60
    Final Stack: [60], Answer = 60

6. Convert the following infix expressions to postfix notation, showing stack and string at each step:


(a) A + B - C * D

Answer: AB+CD*-


(b) A * (( C + D ) / E )

Answer: ACD+E/*


7. Write a program to create a Stack for storing only odd numbers out of all the numbers entered by the user. Display the content of the Stack along with the largest odd number in the Stack. (Hint: Pop all elements, maintain the largest so far.)


Answer:

def push(stack, item):
    stack.append(item)
def pop(stack):
    if stack == []:
        return
    return stack.pop()
def oddStack(num):
    if num % 2 == 1:
        push(stack, num)
def GetLargest(stack):
    elem = pop(stack)
    large = elem
    while elem != None:
        if large < elem:
            large = elem
        elem = pop(stack)
    return large
n = int(input("How many numbers?"))
stack = []
for i in range(n):
    number = int(input("Enter number:"))
    oddStack(number)
print("Stack created is", stack)
bigNum = GetLargest(stack)
print("Largest number in stack", bigNum)

Detailed NCERT Solutions for Class 12 Computer Science Chapter 3 – Stack

Understanding the basics of Stack data structure is crucial in Class 12 Computer Science. With clear concepts and practice, you can apply the LIFO principle and confidently solve Python stack questions in your exams.


The NCERT Solutions Class 12 Computer Science Chapter 3 Stack for 2025-26 guide you through stack operations and their applications. Use algorithm examples and Python implementation tips to strengthen your exam preparation and coding skills.


Regular revision and solving exercise-based questions from this chapter will help you master stack concepts. Focus on the applications, and you’ll be ready to score high in your board exams and future programming challenges.


FAQs on Class 12 Computer Science Chapter 3: Stack – NCERT Solutions & Key Answers

1. What are NCERT Solutions for Class 12 Computer Science Chapter 3 Stack?

NCERT Solutions for Class 12 Computer Science Chapter 3 Stack provide stepwise, exam-focused answers to all questions in Chapter 3 on Stacks. These solutions help students:

  • Understand definition, implementation, and operations (Push/Pop) of stacks as per CBSE syllabus
  • Get stepwise solutions for all intext and back exercises
  • Follow answer structures that match CBSE marking scheme
  • Use clear diagrams, definitions, and examples for full marks

2. How can I write stepwise NCERT answers for full marks in Stack chapter?

To write stepwise NCERT answers for full marks in the Stack chapter, follow these steps:

  • Read and understand the question carefully
  • Start with a definition if the question asks for one
  • Use bullet points or numbered steps for explanations
  • Include diagrams or flowcharts if required (especially for Push/Pop operations)
  • Highlight keywords like LIFO, Push, Pop, overflow, underflow, etc.
  • End with a short summary or conclusion

This structure matches the CBSE marking scheme and covers both theory and practical application.

3. Which Stack-related questions are most likely to appear in CBSE exams?

Some of the most commonly asked stack-related questions in CBSE Class 12 exams include:

  • Define stack and explain its characteristics
  • Write algorithm for Push and Pop operations
  • Implement stack using arrays and write the corresponding code
  • Differentiating stack vs queue
  • Draw diagrams showing Push/Pop or underflow/overflow scenarios
  • Explain real-life applications of stacks

4. Do answers require diagrams, definitions, or both to get full marks?

Yes, to score full marks in Class 12 Computer Science Chapter 3 Stack answers, you should:

  • Include clear, labeled diagrams wherever process or structure is explained
  • Give precise definitions using textbook terminology
  • Combine both for questions on Push, Pop, stack working, and memory representation

This approach follows CBSE guidelines and maximizes scoring potential.

5. How should I structure long answers for maximum scoring in Stack chapter?

For full marks in long answers on stacks, structure your response as follows:

  • Start with a definition and introduction
  • Discuss key concepts or operations stepwise
  • Use algorithms or code examples if asked
  • Provide labeled diagrams
  • Summarize with conclusion or practical applications

Maintain logical flow, use headings, and highlight major points.

6. Where can I download the official solutions PDF for Chapter 3 Stack?

You can download the official NCERT Solutions Class 12 Computer Science Chapter 3 Stack PDF from trusted educational websites such as the official NCERT portal or CBSE-aligned platforms. Look for:

  • Free, chapter-wise downloadable PDFs for offline use
  • Expert-verified solutions matching 2025–26 CBSE syllabus
  • Practice questions and answer-key for all Stack topics

7. Are NCERT Solutions enough for Class 12 Computer Science exams?

NCERT Solutions are sufficient for Class 12 Computer Science exams if you:

  • Revise all chapter exercises, examples, and intext questions
  • Practice stepwise solutions and diagrams
  • Supplement with previous years' papers and sample questions for full coverage

For high scores, combine solutions with quick revision notes and regular practice.

8. What are the most important topics from Class 12 Computer Science Chapter 3 Stack?

The most important topics from Chapter 3 Stack for Class 12 CBSE exams are:

  • Definition and features of stack (LIFO approach)
  • Push and Pop operations (with diagrams and code)
  • Stack implementation using arrays or linked lists
  • Stack overflow and underflow conditions
  • Applications of stack in computer science (e.g., expression evaluation, recursion)

9. How to present long answers to match CBSE marking?

To match CBSE marking for long answers, use the following tips:

  • Answer in parts: definition + main body + diagram + conclusion
  • Highlight keywords and headings
  • Use diagrams with labels wherever required
  • Number steps or points for clarity
  • Quote NCERT terminology for maximum scoring

10. What is a stack in Class 12 Computer Science?

A stack in Class 12 Computer Science is an abstract data structure that follows the Last In First Out (LIFO) principle. Key points include:

  • Elements are inserted (Push) and removed (Pop) from the top only
  • Main operations: Push, Pop, Peek
  • Commonly implemented using arrays or linked lists
  • Used in function calls, expression conversion, and undo operations

11. How to learn diagrams/maps for this chapter?

To effectively learn diagrams for Chapter 3 Stack:

  • Practice drawing labeled diagrams for Push, Pop, and stack representation
  • Follow NCERT diagram conventions
  • Label all parts (top, elements, empty/full conditions)
  • Use neat handwriting and straight arrows

Consistent practice ensures you gain easy marks for diagram-based questions.

12. Do examiners award partial marks for correct steps even if the final answer is wrong?

Yes, in Class 12 Computer Science exams, CBSE examiners award step marks for each correct part of the answer, even if the final step is incorrect. To maximize marks:

  • Show clear steps in algorithms and operations
  • Write each intermediate calculation or code segment
  • Avoid skipping logic or combining steps