I still remember my first data structure class. The teacher filled the board with names – Array, Linked List, Stack, Queue, Tree, Graph. I copied everything into my notebook, went back to my room, and honestly, I was completely confused. Do we really have to learn all of these separately?
A few days later, one small idea cleared everything for me. These names are not random. They are divided into a few types. Once you understand the types, every topic starts falling into its own place. You know where an array belongs, why a queue is different from a tree, and why a graph does not look like either of them.
So in this post, I will explain the types of data structures in the simple way I wish someone had explained them to me at that time. No heavy language, no textbook lines. Just plain English and examples from daily life. If your basics are not clear yet, first read our post on what is a data structure and why does it matter, and then come back here.
Why Are Data Structures Divided Into Types?
Because data is not always the same.
Sometimes data is in a simple line, like the marks of students in a class – roll number 1, 2, 3, 4. Sometimes data looks like folders on a laptop, one folder inside another folder, and a file inside that. And sometimes data is like cities connected by roads on a map, a full network with no clear start or end.
If the nature of the data is different, the way we store it also has to be different. That is the whole reason behind this classification. It is not there to make the subject hard. It is actually there to make it easy.
There are two main divisions you should remember. First, primitive and non-primitive. Second, and this is the one that matters most in exams, non-primitive is further divided into linear and non-linear.
Primitive Data Structures – The Basic Building Blocks
Primitive means basic. These are given by the programming language itself, you do not create them.
int, float, char and boolean – you have already used all of these in C in your first year. An int stores one whole number, like age = 20. A char stores one letter, like grade = ‘A’. A float stores a decimal value, like 45.5. A boolean stores only true or false.
I always explain it with bricks. One brick does not make a building, but you cannot make a building without bricks either. Arrays and linked lists look big from the outside, but inside, they are built from these small values only.
This part carries very few marks in a written exam, but it is a favourite question in viva. So just remember these examples – int, char, float, boolean and pointer. A pointer stores the memory address of another variable.
Non-Primitive Data Structures – Where the Real Subject Begins
Almost everything we study in this subject – array, stack, queue, tree – comes under non-primitive data structures.
They do not store just one value. They store a full collection. The marks of one student is a primitive value. The marks of the whole class, stored roll number wise? For that, you need a non-primitive structure.
If you want a quick one-line revision of all the main structures, you can also open our post on essential data structure insights while reading this. It will help you revise faster.
Now comes the most important part of this post – linear and non-linear.
Linear Data Structures – Everything in One Line
Linear simply means in a line. One element after another. First, second, third. You can start from one end and visit every element in a proper sequence.
Think of students standing in a line at the college canteen. That is exactly the feeling.
Array – This is the first structure almost every student learns. It stores elements of the same type in continuous memory, and every element gets an index number. If you know the index, you can reach the element directly, and that is very fast. But the size is fixed. If you create an array for 50 students and the 51st student joins, you are stuck. Inserting an element in the middle is also painful, because the other elements have to shift.
Linked List – Here data is stored in small units called nodes. Each node holds the data and also the address of the next node, like coaches of a train joined one after another. Memory does not have to be continuous, and the size can grow or shrink whenever needed, so insertion and deletion are easier than in an array. But direct access is lost. If you want the 10th node, you have to walk through the first nine. Interviewers almost always ask about this one disadvantage.
Stack – A stack works on LIFO – Last In, First Out. The element that went in last comes out first. The best example is a pile of plates. You place a new plate on the top, and you also pick a plate from the top. We have explained push, pop and the uses of stack in detail in our post on concepts of stack in data structure.
Queue – A queue feels exactly the opposite. It works on FIFO – First In, First Out. Whoever comes first, goes first. A line at a bus stop, a line at a ticket counter, documents waiting for a printer – all of these are queues.
Non-Linear Data Structures – Not in a Line, and That Is Normal
Please do not get scared by the word non-linear. It only means the data is not stored in a straight line. One element can be connected to many other elements, and there can be more than one level.
Tree – Think of the folders on your laptop, or a family tree drawn on a chart. There is one main element at the top, called the root, and branches come out below it. A tree is the best choice when data is in parent-child form. Binary tree, binary search tree and heap are all forms of a tree. In GATE, a question from tree, especially from tree traversals, is almost certain.
Graph – A graph has no root and no parent. It has points, called vertices, and lines joining them, called edges. Think of Google Maps. Cities are points, roads are lines. The famous shortest path problems come from graphs only.
Hash Table – Hashing is a little different. It stores data as key and value pairs and uses a hash function to directly locate where the data is kept. You do not read a dictionary page by page, you open almost the exact place. Searching is very fast, and that is its biggest strength.
Difference Between Linear and Non-Linear Data Structure
To be honest, this small table has saved many students in viva. The difference question is asked everywhere, in class tests, in semester exams and in interviews.
| Point | Linear Data Structure | Non-Linear Data Structure |
|---|---|---|
| How data is stored | One after another, in a sequence | Not in a sequence, in levels or in a network |
| Traversal | One run is enough to visit all elements | One run is not enough |
| Levels | Only one level | More than one level |
| Implementation | Easier to understand and code | Needs more practice |
| Examples | Array, Linked List, Stack, Queue | Tree, Graph |
Remember this table with examples, and half of this topic is already done for you.
Static and Dynamic Data Structures
There is one more small division, and teachers often ask it right after linear and non-linear, so let us finish it here.
A static data structure has a fixed size. A normal array is static. If you declare 10, it will stay 10.
A dynamic data structure can change its size while the program is running. A linked list is dynamic. Create a node when you need one, remove it when you do not.
There is an interesting point here. Stack and queue can be built in both ways, using an array or using a linked list. So they can be static or dynamic depending on how you implement them. If you mention this in an interview, it shows that you have actually written the code, not just read the theory.
Which Data Structure Should You Use, and When?
In a written exam, you can write definitions and pass. In an interview, they give you a situation and watch what you choose. That is the real skill.
My simple way to decide is this. Need fast access by index again and again? Use an array. Too many insertions and deletions in the middle? A linked list is better. Building an undo feature? That is a stack. Work is coming one by one and should be processed in the same order? Use a queue. Data looks like folders, with levels above and below? Use a tree. Data looks like a network of roads or friends? Use a graph. And if you only need very fast searching by a roll number or a username, think of hashing first.
No data structure is the best for everything. The most common mistake beginners make is using an array for every problem. It works in small college programs. It fails in real projects.
This Is Not Only for Exams
The undo option in a word document is a stack. Your phone playlist, your laptop file system, the shortest route in a map app – the same structures are quietly working behind all of them. We just do not see them.
For GATE CSE students, this is a core subject, not a side topic. The syllabus itself lists recursion, arrays, stacks, queues, linked lists, trees, binary search trees, binary heaps and graphs. If this classification is clear in your mind, revision in the last month becomes much faster. In placement interviews also, the first technical round is mostly this – choose the right structure, write the basic code, and tell the time complexity.
After reading this post, test yourself with these interview questions from data structure. If you can answer most of them without opening a book, your basics are in good shape.
For extra practice, students generally use Programiz for clear theory and GeeksforGeeks for problems. Both are good, as long as you practise daily and do not only read.
Common Questions Students Ask
Q. In short, what are the main types of data structures?
Primitive and non-primitive. Non-primitive is divided into linear and non-linear. That is the main classification, and if someone asks for one more, you can also mention static and dynamic.
Q. Is a stack linear or non-linear?
It is linear. Many students get confused because a stack is drawn growing upwards in diagrams. But the elements still come one after another, so it is a linear data structure.
Q. Which topic should a beginner start with?
Start with the array. Once the array is clear, linked list, stack and queue become much easier, because they all revolve around it. Do not start directly with tree or graph, it will only create confusion.
Q. Which data structure is best for fast searching?
If you only need fast searching, hashing is usually the answer. If the data should also stay in sorted order, think of a binary search tree. The final choice always depends on the problem.
Final Words
If data structures looked like a tough subject when you opened this post, I hope they look a little more sorted now. Primitive means a single value. Non-primitive means a collection. Linear means a line. Non-linear means levels and networks. That is the whole classification.
One last request, and please do not skip this – do not just read this post and close the tab. I used to do the same mistake. Take a notebook, draw the classification chart once with your own hand, and write one daily-life example below each name. That single page will help you in your exam, in your viva, and in your interview.
In the next post in this series, I will write the comparison students ask about the most – array vs linked list, with clear examples and a simple table.