Computer Science · Class 12 Optional
Ch 3Stack — Class 12 Computer Science, concept-first.
In Class XI, you learned about Python's built-in data types like strings, lists, tuples, and sets. These are not just random containers — they are examples of data structures. A data structure defines a mechanism to store, organise and access data, along with the operations that can be efficiently performed on it.
13
Q&A
6
Concepts
40m
Section weightage
Computational Thinking and Programming – 2 · across all 7 lessons
Key concepts
Hover a concept to preview it and jump to its most relevant Q&A.
Infix to Postfix Conversion
Imagine you're giving someone directions. You might say, "Go to the market, then turn left, then buy vegetables." That's a natural, step-by-step order.
Most relevant Q&A
- Let us now use this algorithm (Algorithm 3.1) to convert a given infix expression (x + y)/(z*8) into equivalent postfix expression using a s…Preview
- Figure 3.4 shows the step-by-step process of evaluation of the postfix expression 7 8 2 * 4 / + using Algorithm 3.2. ![A step-by-step evalua…Preview
- 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…Free
- Write a program to reverse a string using stack.Free
- For the following arithmetic expression: ((2+3)*(4/2))+2 Show step-by-step process for matching parentheses using stack data structure.Preview
Chapter contents
The NCERT structure, section by section. Open a section to see its questions, then read the concept-first solution.
Introduction
In Class XI, you learned about Python's built-in data types like strings, lists, tuples, and sets. These are not just random containers — they are examples of data structures.
Stack
A stack is a linear arrangement of elements where all additions and removals happen from the same end — the top. Think of a pile of plates in a kitchen or a stack of books on a table (Figure 3.1).
Applications of Stack
2 QA stack is a data structure that follows the Last In, First Out (LIFO) principle — the last item added is the first one removed.
Operations on Stack
A stack is a structure that implements the LIFO arrangement introduced in the previous section, hence elements are added to and deleted from the stack at one end only.
PUSH and POP Operations
The two fundamental operations on a stack are PUSH and POP. They are the only ways to insert or remove data, and they strictly enforce the LIFO (Last In, First Out) order.
Implementation of Stack in Python
A stack is an ordered, linear collection where all insertions and deletions happen at one end — the top. In Python, the simplest way to build a stack is to use the built-in list type.
Notations for Arithmetic Expressions
We write arithmetic expressions in a natural way, placing operators like +, -, , / between their operands. For example, x + y or 2 - 3 y.
Conversion from Infix to Postfix Notation
2 QHumans naturally understand infix expressions like x + y / z. We know from the BODMAS rule that division has higher precedence than addition, so we evaluate y / z first, even though the + operator app…
+−Worked Examples1 question
+−Think & Reflect1 question
Evaluation of Postfix Expression
2 QWhen you evaluate an arithmetic expression, the usual way — with operators between operands, like 7 + 8 — is called infix notation.
Summary
- Stack is a data structure in which insertion and deletion is done from one end only, usually referred to as TOP.
Exercises
+−Show 7 questionsHide questions7 questions
- Q1State 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…Free
- Q2Find the output of the following code: (a) result=0 numberList=[10,20,30] numberList.append(40) result=result+numberList.pop() result=result…Free
- Q3Write a program to reverse a string using stack.Free
- Q4For the following arithmetic expression: ((2+3)*(4/2))+2 Show step-by-step process for matching parentheses using stack data structure.Preview
- Q5Evaluate following postfix expressions while showing status of stack after each operation given A=3, B=5, C=1, D=4 (a) A B + C * (b) A B * C…Preview
- Q6Convert the following infix notations to postfix notations, showing stack and string contents at each step. (a) A + B - C * D (b) A * (( C +…Preview
- Q7Write 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…Preview