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.
How the items sit. In a row? In a pile? In a line waiting their turn? Branching like a family tree?
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:
marks = [78, 91, 65]
marks.append(88)
marks.insert(1, 70)
marks.remove(65)
print(marks)
print(marks[2])
print(len(marks))[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.
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.
Tap any member to see how it arranges its items and where you may add or take one.
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.
| Linear | Non-linear | |
|---|---|---|
| How items sit | one after another, in a sequence | branching out, or joined up in any pattern |
| The next item | there is exactly one | there can be several, or none |
| Examples | list, stack, queue | tree, graph |
| In your syllabus | the stack | none of them |
5What the syllabus asks, and where each part is taught
Data Structure: Stack, operations on stack (push & pop), implementation of stack using list.
What a stack is, and the one rule that makes it a stack — What is a Stack?
The two operations, plus peek, isEmpty, underflow and overflow — Push and Pop.
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
How the data is arranged, plus the operations allowed on it.
In a row, and you may add, remove and reach items anywhere.
One after another (list, stack, queue) or branching (tree, graph).
A stack can do less than a list, and that is exactly why it is useful.
Which two things make up a data structure?
Which of these is a linear data structure?
A list can already add and remove anywhere. Why use a stack?