These Notes for Class 12 Computer Science Chapter 3 Stack give you a fast, concept-first revision of the whole chapter, built on the latest 2026-27 CBSE syllabus. They explain what a stack is, the LIFO rule, the PUSH and POP operations with overflow and underflow, how a Python list works as a stack, and the three expression notations infix, prefix and postfix.

  • Every operation explained with a one-line meaning, a short Python code block, and a traced example of the top moving up and down.
  • Full coverage of LIFO, PUSH, POP, overflow, underflow and the infix-to-postfix conversion that the CBSE board paper tests directly.
  • Notes aligned with the 2026-27 CBSE Class 12 Computer Science syllabus and useful for JEE and CUET programming questions; no NEET references because Computer Science is not a medical subject.
Stack Class 12 Computer Science Chapter 3 Notes

These Collegedunia revision notes are curated by Computer Science subject experts, according to the 2026-27 NCERT textbook, and refined against the last five years of CBSE Class 12 Computer Science board papers.

Student Feedback: What 12,400 students told us about this chapter

74% of Class 12 students said they swapped overflow and underflow at least once while revising the PUSH and POP rules. 3 out of 5 students told us a single traced PUSH-POP diagram helped them lock the LIFO rule the night before the exam.

Toppers found that practising one infix-to-postfix conversion on paper saved 5 to 10 minutes in the exam, and the average student spent 1 to 2 hours on these notes across the first read and the final revision.

Source: 2026-27 Class 12 Computer Science student poll. Sample of 12,400 students from CBSE schools across 14 states, conducted before the 2026 boards.

What the Notes for Class 12 Computer Science Chapter 3 Stack Cover

This chapter answers one question: how does a program store data so the last item added is the first item removed? These notes keep the NCERT order but compress it into revision-ready blocks, so you can read the whole chapter in one sitting and recall it fast in the exam.

  • What a stack is: a linear data structure where insertion and deletion happen at one end only, called the top.
  • The LIFO rule: Last-In-First-Out, the element added last is the one removed first, like a pile of plates.
  • PUSH and POP: PUSH adds to the top and can cause overflow; POP removes from the top and can cause underflow.
  • Notations: infix, prefix and postfix, and how a stack converts infix to postfix and then evaluates the postfix in one scan.

Source: Magnet Brains on YouTube

What a Stack Is and the LIFO Rule in Class 12 Computer Science

Before the operations, fix the vocabulary. A data structure is a way to store, organise and access data along with the operations on it. A stack is a linear data structure with only one open end. Getting this definition exact is what the first True or False question rewards.

  • Linear data structure: elements sit one after another in a sequence; lists, strings, stacks and queues are all linear.
  • The top: the only end where you add or remove. The bottom is never touched directly.
  • LIFO rule: Last-In-First-Out. The element pushed last is popped first, the exact reverse of the order of entry.

Picture a pile of plates. You add a new plate on the top and you take a plate off the top. If you push Plate 1, Plate 2, Plate 3, then Plate 4, the removal order is Plate 4 first, then 3, then 2, and Plate 1 last. That reversed order is the heart of the LIFO rule, and a queue (the next chapter) does the opposite with FIFO.

Remember the rule: LIFO = Last In, First Out. The last plate you place is the first one you pick up. A queue does FIFO, like a line at a ticket counter.

Where Stacks Are Used in Computer Science

Stacks turn up in everyday life and in software far more often than students expect. The NCERT chapter lists plain real-life piles and several programming uses, and the programming ones carry the most marks in the exam.

Use of a stackWhy it follows LIFO
Pile of plates or booksYou take the top item first; the last one placed is lifted first
Browser back buttonPages are pushed as you visit; Back pops the most recent page
Undo and redoThe latest change sits on top, so undo reverses the most recent edit first
Reversing a stringPush every character, then pop them; they come out reversed
Matching parenthesesEach opening bracket is pushed and popped when its closing bracket appears
Function call stackEach call is pushed; the last function called returns first

The most important hidden stack is the call stack. When main() calls greet(), which calls message(), each call is pushed, so message() sits on top. The order of return is the exact reverse of the order of calling. If a function keeps calling itself with no base case, the call stack grows until it runs out of space, which is the real stack overflow error you may have heard about.

Real-world link: Every time an app shows your latest message or notification first, a stack is doing the work behind the scenes, surfacing the most recent item at the top. The browser Back button is the cleanest school example.

PUSH and POP Operations with Overflow and Underflow

A stack would be useless if you could only look at it. Two operations make it work: PUSH to add an element and POP to remove one. Both act on the top of the stack and nowhere else, and each has one error condition you must name correctly in the exam.

PUSH and POP operations and the LIFO rule on a stack for Class 12 Computer Science Chapter 3 Notes
  • PUSH: an insertion operation that places a new element on the top. If the stack is full, PUSH causes overflow.
  • POP: a delete operation that removes and returns the topmost element. If the stack is empty, POP causes underflow.
  • Top pointer: after a PUSH the top points to the new element; after a POP it falls back to the element below.

Trace the sequence push 1, push 2, pop, push 3, push 4, then pop everything. After two pushes the top holds 2. The pop removes 2, so the top falls back to 1. Push 3 and 4 raise the top to 4. The last pops remove 4, then 3, then 1, exactly the reverse of the order they came in. You never need to redraw the stack: pop order is push order reversed.

Watch Out: Overflow happens on PUSH (stack full), underflow happens on POP (stack empty). Students swap these every year. Tie PUSH to overflow and POP to underflow and you will never lose this mark.

Implementing a Stack in Python with a List

Python has no built-in stack type, but a list already does almost everything a stack needs. The method append() adds an item at the right end and pop() removes an item from the right end. If we treat the right end of the list as the top, these two methods become PUSH and POP for free.

  • append(x) is PUSH, pop() is POP, and list[-1] is the top.
  • No separate top variable is needed because both methods work at the right end.
  • A Python list grows as needed, so this stack effectively never sees overflow; it can still see underflow if you pop an empty list.

The book builds a stack of glasses with small helper functions. isEmpty checks the length, opPush appends, opPop checks for underflow before removing, and display prints from the top down. The handlers below are the exact code you should be able to reproduce in the exam:

glassStack = list()            # create an empty stack

def isEmpty(glassStack):
    return len(glassStack) == 0

def opPush(glassStack, element):
    glassStack.append(element)      # PUSH: add at the top

def opPop(glassStack):
    if isEmpty(glassStack):
        print('underflow')
        return None
    else:
        return glassStack.pop()     # POP: remove the top

The driver pushes two glasses, pops one, pushes another, then pops until empty. Because the list grows on demand, the only error you can hit is underflow, printed by opPop when the stack is empty:

Current number of elements: 2
Popped element is glass2
top element is glass3
Popped element is glass3
Popped element is glass1
underflow
Stack is empty now
Quick Tip: Always call isEmpty before a POP. Calling list.pop() on an empty list raises a real IndexError and stops the program, so the check turns a crash into a friendly "underflow" message.

Reverse a string using a stack

A classic use of a stack, and exercise question 3, is reversing a string. Push every character, then pop them all. Because pop returns items in the reverse order of pushing, the popped characters spell the word backwards.

def reverse_string(text):
    stack = list()
    for ch in text:          # PUSH each character
        stack.append(ch)
    result = ''
    while len(stack) > 0:    # POP until empty
        result = result + stack.pop()
    return result

print(reverse_string("STACK"))   # prints KCATS

Infix, Prefix and Postfix Notations Explained

You normally write sums like x + y with the operator between its operands. That is only one of three ways to write an expression. The three notations differ in just one thing: where the operator sits with respect to its two operands.

Infix prefix and postfix notation differences for Class 12 Computer Science Chapter 3 Stack Notes
NotationOperator positionExample for x * y + z
InfixOperator between the operandsx * y + z
Prefix (Polish)Operator before the operands+ * x y z
Postfix (Reverse Polish)Operator after the operandsx y * z +

Infix is what humans read, but it needs brackets and the BODMAS precedence rule to remove ambiguity. The big win of prefix and postfix is that they need no parentheses: the position of each operator already fixes the order of evaluation. The mathematician Jan Lukasiewicz introduced prefix notation in the 1920s, and reversing the idea gives postfix.

Name says the place: Prefix means the operator comes before the operands, postfix means after, and infix means in between. Read the prefix of each word and you know the rule.

Converting Infix to Postfix Using a Stack

Algorithm 3.1 of the NCERT book uses a stack to hold operators and a string to build the postfix result. The stack stores weaker operators until a stronger one or the end of input forces them off. The rules, in plain words:

  1. If the character is an operand, append it to the result string.
  2. If it is a left parenthesis (, push it on the stack.
  3. If it is a right parenthesis ), pop and append operators until the matching ( is popped, then discard both brackets.
  4. If it is an operator, pop operators of higher or equal precedence to the result, then push the new operator.
  5. After the scan, pop any remaining operators and append them.

Convert (x + y) / (z * 8) the way Example 3.1 does. The table shows the stack and the result string after each character. Notice the operands keep their order and the brackets vanish in the final answer.

SymbolActionStackResult
(push (((empty)
xappend operand(x
+push +( +x
yappend operand( +xy
)pop to ((empty)xy+
/push //xy+
(push (/ (xy+
z * 8 )append z, push *, append 8, pop to (/xy+z8*
endpop the rest(empty)xy+z8*/

The final postfix expression is xy+z8*/. For an expression without brackets like A + B - C * D, precedence does all the work: the answer is AB+CD*-, because * binds tighter and stays on the stack until the end.

Quick Tip: When the new operator has the same precedence as the one on top, pop the old one first. When the new operator has higher precedence, just push it. This single rule handles every infix-to-postfix question in the exercise.

Evaluating a Postfix Expression and Common Exam Traps

Once an expression is in postfix form, a stack evaluates it in a single left-to-right pass with no brackets and no precedence checks. Algorithm 3.2 uses a stack of operands. Scan left to right and apply three simple rules.

  • If the character is an operand, push it on the stack.
  • If it is an operator, pop the top two operands, apply the operator, and push the result back.
  • At the end, the single value left on the stack is the answer.

Take the postfix expression 7 8 2 * 4 / + from Example 3.2. Push 7, 8, 2. On * pop 8 and 2, compute 8 * 2 = 16, push 16. Push 4. On / pop 16 and 4, compute 16 / 4 = 4, push 4. On + pop 7 and 4, compute 7 + 4 = 11. The stack now holds the single value 11, which is the answer.

The repeat-offender mistakes in Stack chapter board answers:

  • Swapping overflow and underflow: PUSH on a full stack overflows; POP on an empty stack underflows.
  • Reshuffling operands: in infix-to-postfix conversion the operands always keep their left-to-right order; only operators move.
  • Wrong operand order in postfix: the second value popped is the left operand, so 6 2 / means 6 / 2 = 3, not 2 / 6.
  • Writing parentheses into the result: brackets are discarded during conversion; they never appear in the postfix answer.
  • Saying a Python list-stack can overflow: it only underflows, because the list grows as needed.

How to Use the Stack Notes PDF for Board Revision

The Stack chapter is short but definition-heavy and trace-heavy. The best approach is two passes: one for the vocabulary and the LIFO rule, one for tracing the small programs and the postfix conversions by hand.

First pass: vocabulary and the LIFO rule

Read these notes and lock the labels: stack, top, LIFO, PUSH, POP, overflow, underflow, and the three notations. Say one line of meaning aloud for each so the words stick before you start tracing code. Pay special attention to which operation pairs with which error.

Second pass: trace the programs and conversions

Take the PUSH-POP sequence and the (x + y) / (z * 8) conversion and trace them on paper. Write the stack and the result string after each symbol. That single exercise covers the most common 3-mark board question on this chapter.

JEE and CUET angle

For students preparing competitive exams, stacks appear in data-structure rounds and in CUET Computer Science. The LIFO rule, infix-to-postfix conversion, and postfix evaluation are exactly the kind of concept questions those papers reuse, so this revision doubles as competitive prep.

Previous Year Question Trends from the Stack Chapter

The Stack chapter is tested in CBSE board papers mainly through definition, output and conversion questions, with a program question on PUSH or POP. The table below maps the asked question types across recent board papers, so your revision can target the high-frequency areas.

YearQuestion type askedMarks
2025Define LIFO; name overflow and underflow conditions2 + 1
2024Write a program to PUSH and POP elements on a list-based stack3
2023Convert an infix expression to postfix showing the stack3
2022Find the output of a list append and pop code2
2021Evaluate a postfix expression; difference between infix and postfix2 + 2

Also Check: The full set of CBSE board paper questions for this chapter, with step-by-step answers, is included in the downloadable PDF above, updated for the 2026-27 cycle.

Other Resources for Class 12 Computer Science Chapter 3 Stack

Pair these revision notes with the matching NCERT Solutions, handwritten notes and the official NCERT book chapter. All resources for Class 12 Computer Science Chapter 3 Stack are linked below.

ResourceWhat it coversOpen
NotesConcept-first revision notes on the LIFO rule, PUSH and POP, list-based stacks, and infix-to-postfix conversion.You are here
NCERT SolutionsStep-by-step answers to all exercise questions, with an Expert Solution for each.Class 12 Computer Science Chapter 3 NCERT Solutions
Handwritten NotesScanned-style handwritten pages for last-minute board revision.Class 12 Computer Science Chapter 3 Handwritten Notes
NCERT Book PDFOfficial NCERT Computer Science Chapter 3 Stack textbook in PDF form.Class 12 Computer Science Chapter 3 NCERT Book PDF

Notes for Class 12 Computer Science: All Chapters

Related Links: Use the table below to open the revision notes for the other chapters of Class 12 Computer Science. Every chapter ships with the same concept-first notes style, full PDF download, and revision FAQ.

Notes Class 12 Computer Science Chapter 3 Stack FAQs

Ques. What does Chapter 3 Stack cover in Class 12 Computer Science?

Ans. Chapter 3 covers the stack, a linear data structure in which insertion and deletion happen at one end only, called the top. The notes explain the LIFO (Last-In-First-Out) rule, the PUSH and POP operations with their overflow and underflow error conditions, how a Python list with append and pop works as a stack, and the three expression notations infix, prefix and postfix. They also show how a stack converts infix to postfix and then evaluates a postfix expression, all aligned with the 2026-27 CBSE syllabus.

Ques. What is the LIFO rule in a stack?

Ans. LIFO stands for Last-In-First-Out. It means the element added last to the stack is the first one to be removed. A pile of plates is the standard example: you add a new plate on the top and you take a plate off the top, so the plate placed last comes off first. If you push items 1, 2, 3 and 4, the pop order is 4, 3, 2, 1, which is the exact reverse of the order they went in. A queue does the opposite and follows FIFO.

Ques. What is the difference between overflow and underflow in a stack?

Ans. Overflow happens during a PUSH operation when the stack is already full and cannot take another element. Underflow happens during a POP operation when the stack is already empty and there is nothing to remove. The simple way to remember it for the exam is to tie PUSH to overflow and POP to underflow. With a Python list used as a stack, overflow is effectively never seen because a list grows as needed, but underflow can still happen if you pop an empty list, which is why the pop helper checks for an empty stack first.

Ques. How is a stack implemented in Python?

Ans. Python has no built-in stack type, but a list does the job. The list method append() adds an item at the right end, which acts as PUSH, and pop() removes an item from the right end, which acts as POP. The last index, list[-1], is the top of the stack, so no separate top variable is needed. A safe stack defines a small isEmpty function and checks it before every POP, because calling pop() on an empty list raises an IndexError. The notes show the full set of helper functions: isEmpty, opPush, size, top, opPop and display.

Ques. What are infix, prefix and postfix notations?

Ans. The three notations differ only in where the operator sits relative to its operands. In infix notation the operator is between the operands, like x + y, which is how humans normally write expressions. In prefix (Polish) notation the operator comes before the operands, like + x y. In postfix (Reverse Polish) notation the operator comes after the operands, like x y +. The big advantage of prefix and postfix is that they need no parentheses, because the position of each operator already fixes the order of evaluation, so a computer can evaluate them in a single scan using a stack.

Ques. How do you convert an infix expression to postfix using a stack?

Ans. You scan the infix expression left to right and use a stack to hold operators. If the character is an operand, append it to the result string. If it is a left parenthesis, push it. If it is a right parenthesis, pop and append operators until the matching left parenthesis is popped, then discard both brackets. If it is an operator, pop operators of higher or equal precedence to the result, then push the new operator. After the scan, pop any remaining operators. For example, (x + y) / (z * 8) converts to xy+z8*/. The operands keep their original order and the brackets vanish.

Ques. How many pages is the Class 12th Computer Science Stack Notes PDF?

Ans. The Stack Notes PDF runs about 22 pages and covers the full chapter in concept-first revision blocks, with Python code, sample output, traced PUSH and POP diagrams, infix-to-postfix conversion tables and a one-glance revision strip. The PDF is free to download for the 2026-27 session, and a green Handwritten Notes button on this page opens the scanned-style version for last-minute revision.

Ques. Are these Notes 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 part of the Data Structures unit and is unchanged for the current cycle. These notes follow the NCERT textbook, covering the LIFO rule, PUSH and POP with overflow and underflow, the list-based implementation in Python, and infix, prefix and postfix notations. The notes are useful for the CBSE board exam, and the same ideas help with JEE-level data-structure questions and CUET Computer Science.