What is a data structure?
A data structure is a way of organising and storing data in memory so it can be used efficiently. Different structures are good at different jobs. An array is great for fast lookups by position, a linked list is great for frequent inserts, and a hash table is great for fast lookups by key. Choosing the right one is the difference between fast and slow code.
- A data structure organises data in memory so it can be accessed and changed efficiently.
- Each structure has strengths: arrays for indexed access, linked lists for inserts, hash tables for key lookups.
- In interviews, picking the right structure for the problem matters more than reciting a definition.
The core idea
Data by itself is just a pile of values. A data structure gives that data a shape so your program can find, add, and remove items quickly. Think of it like the difference between a messy drawer and a labelled filing cabinet.
Common examples
- Array: items in a row, fast access by index.
- Linked list: items linked by pointers, easy to insert and remove.
- Stack: last in first out, like a pile of plates.
- Queue: first in first out, like a line at a shop.
- Hash table: key to value lookups in near constant time.
- Tree and graph: for hierarchical and connected data.
Interviewers care less about the definition and more about whether you can pick the right structure for a problem. Practice saying which structure you would use and why, for example a hash map for counting frequencies.
Frequently asked questions
What is the difference between a data structure and an algorithm?
A data structure is how you store and organise data, while an algorithm is the step by step method that operates on that data. They work together, since the right structure often makes an algorithm faster and simpler.
Which data structure should a beginner learn first?
Start with arrays, then linked lists, stacks, and queues, and finally hash tables and trees. Arrays and hash tables appear in most interview problems, so they give the best return early on.
Are data structures the same in every language?
The concepts are universal but the names differ. A hash table is a dict in Python, a HashMap in Java, and an unordered_map in C++, yet they all do the same job.
Common follow up questions
Related interview questions
Want the full DSA guide?
Read every DSA concept with notes, diagrams, and code in one place. Track your progress as you go.
Open the DSA guide All DSA questions