Skip to content
← Computer Science

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

Start learning — read this chapter →

Key concepts

Hover a concept to preview it and jump to its most relevant Q&A.

Chapter contents

The NCERT structure, section by section. Open a section to see its questions, then read the concept-first solution.

3.1

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.

3.2

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).

3.2.1

Applications of Stack

2 Q

A stack is a data structure that follows the Last In, First Out (LIFO) principle — the last item added is the first one removed.

3.3

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.

3.3.1

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.

3.4

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.

3.5

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.

3.6

Conversion from Infix to Postfix Notation

2 Q

Humans 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…

3.7

Evaluation of Postfix Expression

2 Q

When 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