aloalgo

Data Structures That Appear in 80% of Tech Interviews

Knowing when to use which data structure is half the battle in coding interviews. The right choice can turn an O(n²) solution into O(n), or make an impossible problem trivial. This guide covers the essential data structures, their operations, complexities, and when to reach for each one.
Data Structure Frequency
Based on interview data from top tech companies:
1. Arrays
The most fundamental data structure. Arrays store elements in contiguous memory, enabling O(1) random access by index.
When to Use Arrays
  • You need fast access by index
  • The size is fixed or grows only at the end
  • You're iterating through elements sequentially
  • Memory efficiency matters (no pointer overhead)
2. Hash Maps (Dictionaries)
Hash maps provide O(1) average-case lookup, insert, and delete. They're the secret weapon for optimizing brute force solutions.
When to Use Hash Maps
  • You need fast lookups by key
  • Counting frequencies of elements
  • Checking for duplicates
  • Caching/memoization
  • Two Sum and its variations
Hash Sets
When you only need to track presence (not key-value pairs), use a set. Same O(1) operations as hash maps.
3. Stacks
Last-In-First-Out (LIFO). Think of a stack of plates - you can only add or remove from the top.
When to Use Stacks
  • Matching parentheses/brackets
  • Undo operations
  • DFS (iterative implementation)
  • Expression evaluation
  • Monotonic stack problems (next greater element)
Deep dive: Stack Patterns: More Than Just LIFO
4. Queues
First-In-First-Out (FIFO). Like a line at a store - first person in line is first to be served.
When to Use Queues
  • BFS (level-order traversal)
  • Processing in order of arrival
  • Sliding window maximum (with deque)
  • Task scheduling
5. Linked Lists
Nodes connected by pointers. Unlike arrays, elements aren't contiguous in memory, enabling O(1) insertions and deletions once you have a reference to the node.
When to Use Linked Lists
  • Frequent insertions/deletions at arbitrary positions
  • Unknown size that grows/shrinks frequently
  • Implementing other data structures (stacks, queues, LRU cache)
  • When the problem explicitly uses ListNode
Deep dive: Linked Lists - Why Use Them Instead of Arrays and Common Patterns
6. Trees
Hierarchical data structures with a root node and children. Binary trees have at most two children per node.
When to Use Trees
  • Hierarchical relationships (file systems, org charts)
  • BST for sorted data with O(log n) operations
  • Recursive problem structure
  • Expression parsing
Deep dive: Every Binary Tree Pattern, Finally Explained
7. Heaps (Priority Queues)
A complete binary tree where each parent is smaller (min-heap) or larger (max-heap) than its children. Provides O(log n) insert and O(1) access to min/max.
When to Use Heaps
  • Find K largest/smallest elements
  • Merge K sorted lists
  • Find median from data stream
  • Dijkstra's shortest path
  • Task scheduling by priority
Deep dive: Priority Queue Patterns: Top-K and Beyond
8. Graphs
Nodes (vertices) connected by edges. Can be directed or undirected, weighted or unweighted. Represented as adjacency list or matrix.
When to Use Graphs
  • Network/connection problems
  • Shortest path
  • Dependency resolution (topological sort)
  • Grid problems (implicit graph)
  • Social networks, maps, web crawling
Deep dive: Graph Algorithms Made Simple: BFS, DFS, Dijkstra
9. Tries (Prefix Trees)
Specialized tree for storing strings where each node represents a character. Enables O(m) prefix lookups where m is the word length.
When to Use Tries
  • Autocomplete
  • Spell checking
  • IP routing
  • Word search in grid
  • Prefix matching problems
Deep dive: What Is a Trie? No, That's Not a Typo
Quick Reference: Choosing the Right Structure
Complexity Cheat Sheet
* Average case, O(n) worst case for hash collisions
** O(1) with reference to the node, O(n) to find it first
Common Combinations
Real problems often combine multiple data structures:
  • LRU Cache: Hash Map + Doubly Linked List
  • Find Median: Two Heaps (min + max)
  • Graph BFS/DFS: Graph + Queue/Stack + Hash Set
  • Dijkstra: Graph + Min Heap + Hash Map
  • Top K Frequent: Hash Map + Heap
  • Word Search II: Trie + DFS on Grid
Related Resources
Was this helpful?
© 2026 aloalgo. All rights reserved.