The 8 Data Structures Every Developer Should Know
Arrays, hash maps, linked lists, stacks, queues, trees, heaps and graphs — the data structures that power real software and coding interviews. What each is good at, its Big O, and when to reach for it.
The eight data structures worth knowing cold are arrays, hash maps, linked lists, stacks, queues, trees, heaps and graphs. Each one is just a different trade-off between how fast you can read, search, insert, and delete — and picking the right one is what turns a slow solution into a fast one.
These structures are the backbone of real software and the vocabulary of coding interviews. You do not need to memorise implementations so much as know each one’s strengths, its Big O costs, and the signal that says “reach for this one.”
1. Array — the default
A contiguous block of elements, accessed by index. It is the structure you already use most.
- Great at: instant access by position —
arr[i]is O(1). Iterating in order. - Weak at: inserting or deleting in the middle (everything after shifts, O(n)), and searching by value (O(n) unless sorted).
- Reach for it when: you know positions, or you just need an ordered list to loop over.
2. Hash map — the interview workhorse
Stores key → value pairs with near-instant access by hashing the key. Called objects/Maps in JavaScript, dicts in Python, HashMaps in Java.
- Great at: O(1) average lookup, insert, and delete. Counting, grouping, deduping, and “have I seen this?” checks.
- Weak at: order (use an ordered variant if you need it), and worst-case O(n) if hashing degrades.
- Reach for it when: you find yourself searching a list repeatedly. A hash map is the most common way to drop an O(n²) brute force to O(n).
3. Linked list — pointers, not positions
A chain of nodes, each holding a value and a pointer to the next (and sometimes previous) node.
- Great at: O(1) insert/delete if you already hold the node — no shifting.
- Weak at: access by position (O(n) — you must walk the chain) and extra memory for pointers.
- Reach for it when: you insert and remove constantly at the ends, or you are asked classic pointer problems (reverse a list, detect a cycle, find the middle).
4. Stack — last in, first out
A pile where you only add and remove from the top (LIFO).
- Great at: O(1) push/pop. Anything where the most recent item matters.
- Reach for it when: undo/redo, matching brackets, parsing expressions, depth-first traversal, or unwinding recursion — the call stack is a stack.
5. Queue — first in, first out
A line where you add at the back and remove from the front (FIFO).
- Great at: O(1) enqueue/dequeue. Processing things in arrival order.
- Reach for it when: scheduling, buffering, and especially breadth-first search over trees and graphs.
6. Tree — hierarchy and ordered search
Nodes with a parent and children. The star is the binary search tree (BST), where left < node < right.
- Great at: a balanced BST gives O(log n) search, insert, and delete — and keeps data sorted.
- Weak at: an unbalanced tree degrades to O(n) (a glorified linked list). Real libraries self-balance.
- Reach for it when: you need ordered data with fast inserts, hierarchical data (file systems, the DOM), or prefix lookups (a trie for autocomplete).
7. Heap — always hand me the best one
A tree-shaped structure that keeps the smallest (min-heap) or largest (max-heap) element instantly reachable. The engine behind a priority queue.
- Great at: O(1) peek at the min/max, O(log n) insert and remove.
- Reach for it when: “top K”, “k-th largest”, merging sorted streams, or any time you repeatedly need the current best element.
8. Graph — things and their connections
Nodes (vertices) joined by edges. Trees are just a special case. Roads, social networks, dependencies, and the web are all graphs.
- Great at: modelling relationships and finding paths.
- Traversed with: BFS (a queue — shortest path in unweighted graphs) and DFS (a stack or recursion — exploring fully, cycle detection).
- Reach for it when: “shortest path”, “is everything connected”, “can I order these dependencies”, or “find the cluster”.
The cheat sheet
Average-case costs — this table is most of what interviews test:
| Structure | Access | Search | Insert | Delete | Best at |
|---|---|---|---|---|---|
| Array | O(1) | O(n) | O(n) | O(n) | indexed access |
| Hash map | — | O(1) | O(1) | O(1) | fast lookup |
| Linked list | O(n) | O(n) | O(1)* | O(1)* | end insert/delete |
| Stack | O(n) | O(n) | O(1) | O(1) | LIFO / undo |
| Queue | O(n) | O(n) | O(1) | O(1) | FIFO / BFS |
| BST (balanced) | O(log n) | O(log n) | O(log n) | O(log n) | ordered + fast |
| Heap | O(1) peek | O(n) | O(log n) | O(log n) | min/max, top-K |
*O(1) once you have a reference to the node.
How interviewers test these
Most problems are really “which structure makes this easy?” in disguise:
- “Find two numbers that sum to a target” → hash map.
- “Validate balanced parentheses” → stack.
- “Level-order / shortest path” → queue + BFS.
- “K-th largest element” → heap.
- “Detect a cycle” → linked-list pointers or graph DFS.
Recognising the structure is 80% of the solution; the code is the easy part.
Where this fits
Data structures, Big O, and recursion are the three pillars of interview prep — learn them together, since every structure has a Big O and many are traversed recursively.
Each structure is drawn out as a diagram, with the “when to reach for it” signal spelled out, in our job-ready tier: JavaScript in Three Months, Python in Three Months, and Java in Three Months. For senior and staff prep — self-balancing trees, graph algorithms at scale, and the structure choices behind system design — the for Staff Engineers tier goes deeper: JavaScript, Python, and Java.
Learn what each structure is good at, and choosing the right one becomes automatic.
Frequently asked questions
Which data structures should I learn first for interviews?
Start with arrays and hash maps — together they solve a huge share of interview problems. Then add stacks and queues, then trees and graphs (with BFS and DFS), and finally heaps. That order matches both frequency in interviews and how the concepts build on each other.
What is the difference between an array and a linked list?
An array stores elements in one contiguous block, so access by index is O(1) but inserting in the middle is O(n) because elements must shift. A linked list stores elements as separate nodes connected by pointers, so inserting or deleting is O(1) if you have the node, but access by position is O(n) because you must walk the chain.
When should I use a hash map?
Whenever you need fast lookup, insertion, or 'have I seen this before?' checks — all O(1) on average. Hash maps are the single most useful interview tool, turning many O(n²) brute-force solutions into O(n).
What is the difference between a stack and a queue?
A stack is last-in-first-out (LIFO) — like a stack of plates, you take from the top. A queue is first-in-first-out (FIFO) — like a line, the first in is the first out. Stacks power undo and recursion; queues power scheduling and breadth-first search.