ADTs vs data structures
Two concepts here often get confused.
Abstract data types (ADTs)
An ADT defines what you can do: which operations exist and how they are expected to behave. It is the interface contract. An ADT says "you can push and pop" without saying how that works under the hood.
Data structures
A data structure defines how it is done: the concrete implementation in memory. It shows exactly how bytes are organized and manipulated.
Practical example
A "stack" is an ADT that defines behavior. You can implement it with an array or with a linked list, two different data structures with the same abstract behavior. The choice affects performance, and the ADT stays the same.
Logical data organization
The first way to classify a structure is by how its elements relate to each other.
Linear structures
Linear structures have a clear sequential order: there's a first element, a last one, and every element in between has exactly one predecessor and one successor. It works like a line of people, where you know who's in front of you and who's behind.
Linear structure examples
Arrays, linked lists, stacks, and queues are the classic examples. A stack is a pile of plates where you only reach the top one. A queue is a bank line: first come, first served. The linearity is in how elements relate to each other, which doesn't have to match how they sit in memory.
Non-linear structures
Non-linear structures drop the single sequence. An element can connect to several others at once, forming hierarchies or networks, as in a family tree or a social network.
Non-linear structure examples
Trees organize data hierarchically, like folders and files on your computer. Graphs represent arbitrary networks, like routes between cities or connections in a social network. Hash tables use a mathematical function to spread data out and jump straight to an entry, a bit like a book index.
Memory perspective
Beyond logical organization, there's the physical question: how are bytes arranged in RAM?
Contiguous memory
In contiguous memory, elements sit in adjacent, sequential positions, like houses numbered in order along a street.
Array: [42, 17, 93, 28]
Arrays work this way. Each element takes 4 bytes, so array[2] is at base_address + (2 × 4), and access takes . Inserting in the middle is the expensive part: every following element has to shift, like reorganizing a whole bookshelf to fit one book in the middle.
Non-contiguous memory
In non-contiguous memory, elements are scattered across different regions and connected by pointers, like a treasure hunt where each clue points to the next.
Linked list: 10 → 20 → 30 → NULL
Linked lists work this way. Each node carries its data and a pointer to the next. Inserting in the middle only means redirecting two pointers, but reaching element 100 means following 100 clues in sequence, which is .
What makes them different
Each data structure makes tradeoffs along these lines:
- Memory layout: contiguous (arrays) or scattered (linked lists)
- Access patterns: random access or sequential traversal
- Operation costs: fast insertions but slow searches, or the other way around
- Space overhead: minimal metadata or pointer-heavy structures
The right choice depends on what you need: hash tables for fast searches, binary search trees to keep data in order, and stacks for LIFO behavior.