The NCERT Solutions for Class 12 Computer Science Chapter 3 Stack cover all 7 exercise questions, according to the latest 2026-27 CBSE syllabus. Every answer follows the textbook's own flow: the LIFO rule of a stack, PUSH and POP with Python lists, and how a stack reverses strings, matches parentheses, and evaluates and converts arithmetic expressions.
- All 7 NCERT questions solved with Python code, dry-run traces, and an Expert Solution per question that adds exam strategy and common-trap warnings.
- Full coverage of LIFO, overflow and underflow, infix to postfix conversion, postfix evaluation, and parenthesis matching that the CBSE board paper tests directly.
- Answers aligned with the 2026-27 CBSE Class 12 Computer Science syllabus and useful for JEE and CUET data-structure questions; no NEET references because Computer Science is not a medical subject.

Every answer in this Collegedunia compilation is curated by Computer Science subject experts, mapped to the 2026-27 NCERT textbook, and refined against the last five years of CBSE Class 12 Computer Science board papers.
Student Feedback: What 11,400 students told us about this chapter
68% of Class 12 students said the infix to postfix conversion was the hardest part of the Stack chapter. 3 out of 5 students told us they lost marks by swapping the left and right operands during postfix evaluation.
Toppers found that drawing the stack and output columns after every symbol added 1 to 2 marks on the 3-mark conversion question, and the average student spent 2 to 3 hours on this chapter across the first read and exercise practice.
Source: 2026-27 Class 12 Computer Science student poll. Sample of 11,400 students from CBSE schools across 13 states, conducted before the 2026 boards.
What the NCERT Solutions for Class 12 Computer Science Chapter 3 Stack Cover
This chapter answers one question: what is a stack, and how do you use it to solve real problems? The NCERT book builds the answer in clear blocks, and these solutions stay faithful to that order while filling the gaps students hit in the exam.
- Stack basics and the LIFO rule: a stack is a linear structure where you PUSH and POP only at the top, so the last item in is the first item out.
- Overflow and underflow: PUSH on a full stack causes overflow; POP on an empty stack causes underflow. These two words are the most common 1-mark trap.
- Stack with Python lists:
append()is PUSH andpop()is POP, so a list is a ready-made stack. - Applications: reversing a string, matching parentheses, infix to postfix conversion, and postfix evaluation, all worked with step-by-step stack traces.
Source: Magnet Brains on YouTube
Exercise-wise Breakdown of the Stack Chapter NCERT Solutions
Chapter 3 of NCERT Class 12 Computer Science carries 7 end-of-chapter exercise questions. The table below maps each question to its topic, the answer style CBSE rewards, and the typical mark weight students see in the board paper.
| Question | Topic covered | Answer style | Typical marks |
|---|---|---|---|
| Q 1 | TRUE or FALSE on linear structure, LIFO, underflow, postfix | One word per part with a reason for FALSE lines | 1 mark each (4 parts) |
| Q 2 | Find the output of two list-as-stack programs | Dry run with the list state shown per line | 2 to 3 marks each |
| Q 3 | Program to reverse a string using a stack | PUSH loop, POP loop, sample run | 3 to 4 marks |
| Q 4 | Match parentheses for an arithmetic expression | Stack status after every character | 3 marks |
| Q 5 | Evaluate two postfix expressions | Stack contents after each token | 3 marks each |
| Q 6 | Convert two infix expressions to postfix | Stack and output columns per symbol | 3 marks each |
| Q 7 | Stack of odd numbers with the largest odd | Full program with a sample run | 4 to 5 marks |
The two program questions (Q 3 and Q 7) and the conversion question (Q 6) carry the heaviest marks. Students who show the PUSH and POP loops clearly and draw the stack trace consistently score full marks.

Stack and the LIFO Rule: PUSH, POP, Overflow and Underflow
A stack is a linear data structure with one open end, called the top. You add and remove items only at the top, so the item added last is the item removed first. This is the LIFO rule: Last In, First Out. A pile of plates is the classic picture, where you take the top plate first.
- PUSH: add an item to the top of the stack. In Python,
stack.append(x). - POP: remove and return the top item. In Python,
stack.pop(). - Overflow: trying to PUSH when the stack has no free space. Only PUSH can cause it.
- Underflow: trying to POP when the stack is already empty. Only POP can cause it.
Because a stack hands items back in reverse order, it is the natural tool for any task that needs reversal or back-tracking. The next sections show four such tasks straight from the NCERT exercise.
Stack with Python Lists: append() and pop()
The NCERT chapter uses a Python list as a stack, so you do not have to build one from scratch. append(x) adds x at the end of the list, which acts as the top, and pop() with no argument removes and returns that same end. This makes the list both the storage and the stack pointer.
stack = []
stack.append(10) # PUSH 10 -> [10]
stack.append(20) # PUSH 20 -> [10, 20]
top = stack.pop() # POP -> returns 20, list is [10]
empty = len(stack) == 0 # test for empty stack
Tracing Q 2 makes the LIFO order concrete. After append(40) the list [10,20,30,40] has 40 on top, so the first pop() returns 40 and the second returns 30, giving result = 70. In part (b), pushing 'T', 'A', 'M' and popping returns M, A, T, so the string builds up to MAT.
Reversing a String and Matching Parentheses Using a Stack
Two of the most asked applications are string reversal and parenthesis matching. Both rely on the same LIFO behaviour, and both appear almost every year in some form.
Reverse a string (Q 3)
PUSH every character of the string, then POP until the stack is empty. The first character popped is the last one pushed, so reading the popped characters gives the string backwards.
def reverse_string(text):
stack = []
for ch in text:
stack.append(ch) # PUSH every character
reversed_text = ""
while len(stack) != 0: # until the stack is empty
reversed_text = reversed_text + stack.pop() # POP top char
return reversed_text
For input HELLO the program prints OLLEH. Python can also reverse with slicing (text[::-1]), but if the question says "using stack" then slicing earns no method marks because it skips the data structure.
Match parentheses (Q 4)
Scan the expression left to right. PUSH each ( and POP one ( on each ). Digits and operators are ignored. The brackets are balanced only if the stack ends empty and you never POP an empty stack.
- For
((2+3)*(4/2))+2, the stack rises to two openers, falls, rises again, and falls to empty. - Two failure tests, not one: a
)arriving on an empty stack, or the scan ending with openers still on the stack.
Tip: State both failure tests in your answer to show full understanding, even when the given expression is balanced.

Infix to Postfix Conversion and Postfix Evaluation
The two expression questions, Q 5 and Q 6, are where most students lose marks. Both use a stack, but in different ways, so keep their rules separate.
Postfix evaluation (Q 5)
Scan left to right. PUSH each operand value. On each operator, POP the top two values, apply the operator, and PUSH the result. The value popped first is the right operand; the value popped second is the left operand. The single value left at the end is the answer.
- With A=3, B=5, C=1, D=4, the expression
A B + C *gives 3+5=8, then 8×1, so the answer is 8. A B * C / D *gives 3×5=15, then 15÷1=15, then 15×4, so the answer is 60.- Order matters only for subtraction and division: compute second-popped operator first-popped.
Infix to postfix (Q 6)
Keep an operator stack and an output string. An operand goes to the output. A ( is pushed. A ) pops to the output until the matching ( is removed. An operator pops every operator of higher or equal precedence first, then pushes itself, where * and / outrank + and -.
| Infix expression | Postfix result | Key step |
|---|---|---|
A + B - C * D | AB+CD*- | Equal precedence: the minus pops the plus first |
A * (( C + D)/E) | ACD+E/* | Brackets block popping and never reach the output |
( or ) shows up in your output, you missed a pop step.
Common Mistakes Students Make in the Stack Chapter
The repeat-offender mistakes in Stack chapter board answers:
- Swapping overflow and underflow: PUSH causes overflow, POP causes underflow. Statement (c) in Q 1 is false only because it pairs PUSH with underflow.
- Adding the wrong two values in a pop trace:
pop()always returns the current top. In Q 2 part (a) the answer is 70, not 30 or 50. - Reversing with a counter loop: reading
stack[i]from the front keeps the original order. You must take from the top withpop(). - Wrong operand order in division: for
C /compute left divided by right, that is 15 divided by 1, not 1 divided by 15. - Copying brackets into the postfix output: parentheses only steer the stack and must vanish from the final string.
How to Use the Stack NCERT Solutions PDF for Board Prep
The Stack chapter is short but trap-heavy. The best approach is two passes: one for the LIFO concept and the Python methods, one for tracing the four applications by hand.
First pass: concept and methods (1 hour)
Read the chapter and note the LIFO rule, the overflow versus underflow pair, and the two list methods append() and pop(). Write one line of meaning next to each so the words stick before you start tracing.
Second pass: trace the applications (1.5 to 2 hours)
Work Q 2, Q 4, Q 5 and Q 6 on paper first, drawing the stack after every symbol. Then open these solutions and check your traces. Pay attention to operand order in division and to brackets never reaching the postfix output, because these two specifics decide full marks.
JEE and CUET angle
For students preparing competitive exams, stacks appear in data-structure questions in JEE-level programming rounds and in CUET Computer Science. Postfix evaluation and parenthesis matching are exactly the kind of trace questions those papers reuse, so the work here doubles as competitive prep.
Previous Year Question Trends from the Stack Chapter
The Stack chapter is tested in CBSE board papers mainly through output and trace questions, with a program question on string reversal or the odd-number stack. The table below maps the asked question types across recent board papers.
| Year | Question type asked | Marks |
|---|---|---|
| 2025 | Find the output of a list-as-stack program; define overflow | 2 + 1 |
| 2024 | Write a program to push and pop elements; evaluate a postfix expression | 3 + 3 |
| 2023 | Convert an infix expression to postfix showing the stack | 3 |
| 2022 | State LIFO; reverse a string using a stack | 1 + 3 |
| 2021 | Difference between overflow and underflow; postfix evaluation | 2 + 3 |
Also Check: The full set of CBSE board paper questions for this chapter is included in the downloadable PDF above, updated for the 2026-27 cycle.
Other Resources for Class 12 Computer Science Chapter 3 Stack
Pair this NCERT Solutions PDF with the matching revision notes, handwritten notes and the official NCERT book chapter. All resources for Class 12 Computer Science Chapter 3 Stack are linked below.
| Resource | What it covers | Open |
|---|---|---|
| NCERT Solutions | Step-by-step answers to all 7 exercise questions, with an Expert Solution for each. | You are here |
| Notes | Concept-first revision notes on LIFO, PUSH and POP, and the four stack applications. | Class 12 Computer Science Chapter 3 Notes |
| Handwritten Notes | Scanned-style handwritten pages for last-minute board revision. | Class 12 Computer Science Chapter 3 Handwritten Notes |
| NCERT Book PDF | Official NCERT Computer Science Chapter 3 Stack textbook in PDF form. | Class 12 Computer Science Chapter 3 NCERT Book PDF |
NCERT Solutions for Class 12 Computer Science: All Chapters
Related Links: Use the table below to open the NCERT Solutions for the other chapters of Class 12 Computer Science. Every chapter ships with the same step-by-step answer style, full PDF download, and revision FAQ.
| Chapter | NCERT Solutions link |
|---|---|
| Chapter 1 | Exception Handling in Python NCERT Solutions |
| Chapter 2 | File Handling in Python NCERT Solutions |
| Chapter 3 | Stack NCERT Solutions (You are here) |
| Chapter 4 | Queue NCERT Solutions |
| Chapter 5 | Sorting NCERT Solutions |
| Chapter 6 | Searching NCERT Solutions |
| Chapter 7 | Understanding Data NCERT Solutions |
| Chapter 8 | Database Concepts NCERT Solutions |
| Chapter 9 | Structured Query Language (SQL) NCERT Solutions |
| Chapter 10 | Computer Networks NCERT Solutions |
| Chapter 11 | Data Communication NCERT Solutions |
| Chapter 12 | Security Aspects NCERT Solutions |
All NCERT Solutions for Class 12 Computer Science Chapter 3 Stack with Step-by-Step Solutions
State TRUE or FALSE for the following cases:
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
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)
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)Write a program to reverse a string using stack.
For the following arithmetic expression: ((2+3)*(4/2))+2
Show the step-by-step process for matching parentheses using the stack data structure.
Evaluate the following postfix expressions while showing the status of the stack after each operation, given A=3, B=5, C=1, D=4:
a) A B + C *
b) A B * C / D *
Convert the following infix notations to postfix notations, showing stack and string contents at each step:
a) A + B - C * D
b) A * (( C + D)/E)
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: keep popping out the elements from the stack and maintain the largest element retrieved so far in a variable. Repeat till the Stack is empty.)
NCERT Solutions Class 12 Computer Science Chapter 3 Stack FAQs
Ques. How many questions are there in NCERT Class 12 Computer Science Chapter 3 Stack?
Ans. There are 7 end-of-chapter exercise questions in NCERT Class 12 Computer Science Chapter 3 Stack. All 7 are solved with full answers and an Expert Solution in the PDF. The mix is one TRUE or FALSE block, one output-finding question, two program questions (string reversal and an odd-number stack), one parenthesis-matching question, one postfix evaluation question, and one infix to postfix conversion question.
Ques. What is the difference between overflow and underflow in a stack?
Ans. Overflow happens when you try to PUSH a new element onto a stack that is already full and has no free space. Underflow happens when you try to POP an element from a stack that is already empty. The simple way to remember it is that PUSH alone can cause overflow, because only PUSH adds elements, and POP alone can cause underflow, because only POP removes them. This is why the statement "PUSH may result into underflow" in Question 1 is false.
Ques. How do you reverse a string using a stack in Class 12 Computer Science?
Ans. Use a Python list as the stack. PUSH every character of the string with append(), then run a loop that POPs the top character with pop() until the stack is empty, joining each popped character to a new string. Because a stack follows the LIFO rule, the last character pushed is the first one popped, so the new string comes out reversed. For input HELLO the program prints OLLEH. The marks are for the PUSH loop and the POP loop, so do not use slicing as a shortcut.
Ques. How do you evaluate a postfix expression using a stack?
Ans. Scan the postfix expression left to right. When you meet an operand, PUSH its value onto the stack. When you meet an operator, POP the top two values, apply the operator, and PUSH the result back. The value popped first is the right operand and the value popped second is the left operand, which matters for subtraction and division. After the whole expression is read, the single value left on the stack is the answer. For A B + C * with A=3, B=5, C=1 the answer is 8.
Ques. How do you convert an infix expression to postfix using a stack?
Ans. Keep an operator stack and an output string and scan left to right. Send each operand straight to the output. Push a left parenthesis. On a right parenthesis, pop operators to the output until the matching left parenthesis is removed and discarded. On an operator, pop every operator of higher or equal precedence first, then push the new operator, where multiply and divide outrank add and subtract. At the end, pop any remaining operators. For A + B - C * D the postfix result is AB+CD*-.
Ques. How many pages is the Class 12th Computer Science Stack NCERT Solutions PDF?
Ans. The Stack NCERT Solutions PDF runs about 17 pages and covers all 7 exercise questions with step-by-step Python code, dry-run traces, stack diagrams, and an Expert Solution for each question. Both Normal and HD versions are available from this page, and both are free to download for the 2026-27 session.
Ques. Is the NCERT Solutions for Class 12 Computer Science Chapter 3 aligned with the 2026-27 syllabus?
Ans. Yes. This page reflects the current 2026-27 CBSE syllabus for Class 12 Computer Science. The Stack chapter is unchanged for the current cycle, and every answer follows the NCERT textbook, including Algorithm 3.1 for infix to postfix conversion and Algorithm 3.2 for postfix evaluation. The solutions are useful for the CBSE board exam, and the same data-structure ideas help with JEE-level programming and CUET Computer Science.
Ques. Why does a stack reverse a sequence?
Ans. A stack reverses a sequence because of the LIFO rule, which means Last In, First Out. When you PUSH the items of a sequence one by one, the first item sits at the bottom and the last item sits on top. When you then POP, you always remove the top first, so the items come out in the opposite order to which they went in. This is exactly why pushing the characters of a string and popping them prints the string backwards, and it is the idea behind Question 2 part (b) and Question 3.








Comments