LambdaLabTM
Computer Science · Class 12 · Data Structures
data structuresintroduction⏱️ 8 min read

What is a Data Structure?

You have used a data structure since Class 11 without calling it one. A list keeps many values under one name, in order, and lets you add them, remove them and reach them. That is all the name means: a way to store data, plus the rules for using it.

1A definition in two halves

A data structure is a way of arranging data in memory, together with the operations you can perform on it.

1 · The arrangement

How the items sit. In a row? In a pile? In a line waiting their turn? Branching like a family tree?

2 · The operations

What you are allowed to do with them. Add an item, remove one, look at one — and where you are allowed to do it.

Both halves matter. The same four numbers can sit in two different data structures, and what makes them different is not the numbers but the rules.

2The one you already know

A Python list is a data structure. Here are four operations on one list, each at a different place in it:

list_operations.py
marks = [78, 91, 65]

marks.append(88)
marks.insert(1, 70)
marks.remove(65)

print(marks)
print(marks[2])
print(len(marks))
Output
[78, 70, 91, 88]
91
4
marks.append(88)

Adds at the end.

marks.insert(1, 70)

Adds in the middle, at position 1. Everything after it moves along one place.

marks.remove(65)

Takes an item out from wherever it happens to be.

marks[2]

Reaches straight to position 2, without touching anything else.

A list lets you work at the front, the back and anywhere in between. Remember that freedom. The stack takes most of it away, on purpose.

3Why would anyone want more rules?

If a list can do everything, why learn a structure that can do less? Because some jobs only ever need the most recent item.

Think of the Undo button. When you press it, you want your last change undone — not a change from ten minutes ago in the middle of your work. A structure that can only give back the most recent item can never give back the wrong one. The rule is not a limitation. It is the whole point.

A stack is a list with a promise
In Python a stack is not a new kind of box. It is an ordinary list that you promise to use in one way only. The next two lessons explain that way without any code. The three after them build it in Python.

4Where the stack fits in the family

Data structures come in two families. In a linear one, the items sit one after another, so every item has a next item. In a non-linear one, an item can lead to several others, or be joined to anything.

🗺️ The data structure family

Tap any member to see how it arranges its items and where you may add or take one.

Linear
items one after another, in a sequence
Non-linear
items branch out or join up
78916588
← in and out
Stack

How the items sit: In a pile, one on top of another.

Where you add and take: Add and remove at ONE end only, called the top. The last item in is the first one out.

Where you meet it: A pile of plates, the Undo button, the Back button in a browser.

Two families
LinearNon-linear
How items sitone after another, in a sequencebranching out, or joined up in any pattern
The next itemthere is exactly onethere can be several, or none
Exampleslist, stack, queuetree, graph
In your syllabusthe stacknone of them
Only the stack is examined
Queues, trees and graphs are real and used everywhere, but they are not in the CBSE Class 12 Computer Science syllabus. Knowing their names helps you see where a stack fits. You will not be asked to write them.

5What the syllabus asks, and where each part is taught

📜 The CBSE syllabus line

Data Structure: Stack, operations on stack (push & pop), implementation of stack using list.

Stack

What a stack is, and the one rule that makes it a stack — What is a Stack?

operations on stack (push & pop)

The two operations, plus peek, isEmpty, underflow and overflow — Push and Pop.

implementation of stack using list

The list methods that do each job, the functions board questions ask for, and a full menu program — the Stack Using a List lessons.

The chapter ends with board and sample-paper questions from 2022 onwards, each one run and explained.

6Recap

Data structure

How the data is arranged, plus the operations allowed on it.

A list is one

In a row, and you may add, remove and reach items anywhere.

Linear vs non-linear

One after another (list, stack, queue) or branching (tree, graph).

Rules are the point

A stack can do less than a list, and that is exactly why it is useful.

Quick Check

Which two things make up a data structure?

Quick Check

Which of these is a linear data structure?

Quick Check

A list can already add and remove anywhere. Why use a stack?