Theory
Same slips, three drawers
The canteen keeps every order slip of the day. Three ways to store them:
- Tossed loose in a drawer.
- Spiked on a nail, newest on top.
- Clipped in a tray, oldest at the front.
Same 500 slips. But try answering "what came in just now?" or "who is next?" and each drawer performs completely differently.
How you arrange data decides how fast you can use it. That single sentence is the entire second half of this subject.
Theory
The kitchen is already organized
Look around the canteen: plates stacked (take from top), customers in a line (serve the first), the menu board as a hierarchy (sections, then dishes), the delivery map as a network of roads.
Nobody stores plates in a queue or customers in a pile. Each arrangement was chosen because it makes one job effortless. Data structures are these arrangements, written in code.
Theory
Data structure, formally
A data structure is a particular way of organizing and storing data in memory so that it can be accessed and modified efficiently.
The classification exams draw:
Data structures
├── Primitive: int, char, float, double
└── Non-primitive
├── Linear: array, stack, queue, linked list
└── Non-linear: tree, graph
Linear structures keep elements in a sequence, one after another. Non-linear structures branch (trees) or interconnect (graphs).
At a glance
Who is used where (the application-areas table)
| Structure | Shape | Real applications |
|---|---|---|
| Array | Numbered row | Marksheets, lookup tables, matrices |
| Stack | Pile, top only | Function calls, undo, infix to postfix |
| Queue | Line, both ends | Token systems, printer jobs, CPU scheduling |
| Linked list | Chain of nodes | Playlists, dynamic memory allocation |
| Tree | Hierarchy | File systems, database indexes, HTML DOM |
| Graph | Network | Google Maps routes, social networks |
Quiz
The canteen prints tokens and serves customers strictly in arrival order. The printer inside queues jobs the same way. Which structure models BOTH, and why?
- Queue: first in, first out matches arrival-order service
- Stack: the last token printed is served first
- Tree: customers branch into veg and non-veg
- Array: tokens have numbers, so an array is required
Show the answer
Queue: first in, first out matches arrival-order service
Arrival-order service is FIFO, the queue's definition, and printer spooling is the textbook queue application. A stack would serve the newest customer first (imagine the queue riots). Numbered tokens do not force an array: the numbering is what the queue hands out, not how memory must be arranged. Matching behaviour to structure, not surface details, is the exam skill.
Think first
Choose the drawer
Three needs: (1) the browser's Back button, (2) the college's folder-inside-folder file explorer, (3) finding the shortest route between two campus gates. Before tapping, assign each a structure from the table.
Show the answer
(1) Stack: Back returns to the most recent page, LIFO.
(2) Tree: folders inside folders is a hierarchy with one root.
(3) Graph: gates and paths form a network, and shortest-route questions are graph questions.
If you got all three, you already think in data structures; the coming lessons only add the mechanics.
Watch out
The classification slip-up
Students write "array, stack, queue, tree" as linear structures: tree is non-linear, it branches. The reliable test: can you walk the whole structure in one straight pass without choosing a branch? Arrays, stacks, queues, linked lists: yes, linear. Trees and graphs: no, non-linear.
Also keep primitive vs non-primitive separate from linear vs non-linear: the second split applies only inside non-primitive.
Theory
Why companies test this in interviews
Wirth's famous book title says it all: Algorithms + Data Structures = Programs. Every slow app you have used was usually the right algorithm on the wrong structure. You already hold two structures from this subject (the plate-pile stack and the token-line queue); the remaining lessons make you implement and apply them.
Summary
Key takeaways
- A data structure is a chosen arrangement of data in memory for efficient access and change.
- Primitive (int, char, float) vs non-primitive; non-primitive splits into linear and non-linear.
- Linear: array, stack, queue, linked list. Non-linear: tree, graph.
- Applications: stack for calls/undo, queue for scheduling, tree for hierarchies, graph for networks.
- The one-straight-pass test separates linear from non-linear.
- Memory hook: same slips, three drawers.