Notes · Class 12 · CBSE · Science Computer Science
Stack notes
Revision notes for the chapter: the key points, definitions and exam tips to remember.
A stack is a linear data structure that follows LIFO — Last In, First Out.
OPERATIONS
- PUSH: add to the top.
- POP: remove from the top.
- PEEK/TOP: view the top element.
- isEmpty: check underflow before popping. (Overflow when a fixed-size stack is full.)
IMPLEMENTATION IN PYTHON
- Use a list: stack.append(x) to push; stack.pop() to pop; stack[-1] to peek; len(stack) == 0 for empty.
APPLICATIONS
- Undo/redo, browser back button, function calls (call stack), reversing a string, matching parentheses.
EXPRESSION NOTATION
- Infix (A + B), prefix (+AB), postfix (AB+).
- Infix to postfix conversion uses a stack for operators (respect precedence and brackets).
- Evaluating postfix: push operands; on an operator, pop two, apply, push result.
Memory hook: "A stack of plates — the last one placed is the first taken."
Stack: practice questionsStack cheat sheet
More Class 12 · CBSE · Science Computer Science notes
Practise Stack
Sign up free to practise the full chapter after revising. Questions you get wrong come back until you've mastered them.
Start practising freeFree to start · No credit card needed