Data Structures for Systems
Data Structures Reference
Essential data structures for system design and algorithm implementation
Array
Fixed-size sequential collection of elements of the same type
Time Complexity
Space Complexity
O(n)Best Use Case:
When you need fast random access to elements by index
Advantages:
- +Constant time access by index
- +Memory efficient
- +Cache-friendly due to locality
Disadvantages:
- -Fixed size in most languages
- -Expensive insertion/deletion
- -Memory waste if not fully utilized
System Design Applications:
Common Examples:
Linked List
Dynamic data structure where elements are stored in nodes with pointers
Time Complexity
Space Complexity
O(n)Best Use Case:
When you need frequent insertions/deletions and don't need random access
Advantages:
- +Dynamic size
- +Efficient insertion/deletion
- +Memory efficient for sparse data
Disadvantages:
- -No random access
- -Extra memory for pointers
- -Not cache-friendly
System Design Applications:
Common Examples:
Stack
LIFO (Last In, First Out) data structure
Time Complexity
Space Complexity
O(n)Best Use Case:
When you need LIFO behavior for temporary storage
Advantages:
- +Simple implementation
- +Constant time push/pop
- +Memory efficient
Disadvantages:
- -Limited access pattern
- -No random access
- -Can overflow if not managed
System Design Applications:
Common Examples:
Queue
FIFO (First In, First Out) data structure
Time Complexity
Space Complexity
O(n)Best Use Case:
When you need FIFO behavior for processing elements in order
Advantages:
- +Fair processing order
- +Constant time enqueue/dequeue
- +Natural for producer-consumer
Disadvantages:
- -No random access
- -Limited access pattern
- -Memory overhead for pointers
System Design Applications:
Common Examples:
Binary Tree
Hierarchical structure where each node has at most two children
Time Complexity
Space Complexity
O(n)Best Use Case:
When you need hierarchical data organization with efficient search
Advantages:
- +Logarithmic time operations
- +Natural hierarchical representation
- +Efficient for sorted data
Disadvantages:
- -Can become unbalanced
- -Complex implementation
- -Overhead for balancing
System Design Applications:
Common Examples:
Heap
Complete binary tree with heap property (min-heap or max-heap)
Time Complexity
Space Complexity
O(n)Best Use Case:
When you need efficient access to minimum/maximum element
Advantages:
- +Constant time access to min/max
- +Efficient insertion/deletion
- +Space efficient (array-based)
Disadvantages:
- -No efficient search for arbitrary elements
- -Not suitable for sorted iteration
- -Complex deletion of arbitrary elements
System Design Applications:
Common Examples:
Trie (Prefix Tree)
Tree structure for storing strings with common prefixes
Time Complexity
Space Complexity
O(ALPHABET_SIZE * N * M)Best Use Case:
When you need efficient prefix-based string operations
Advantages:
- +Fast prefix matching
- +Space efficient for common prefixes
- +Supports autocomplete
Disadvantages:
- -High memory usage
- -Complex implementation
- -Not suitable for general data
System Design Applications:
Common Examples:
Hash Table
Data structure that maps keys to values using hash functions
Time Complexity
Space Complexity
O(n)Best Use Case:
When you need fast key-value lookups and don't need ordering
Advantages:
- +Constant time operations (average)
- +Flexible key types
- +Memory efficient
Disadvantages:
- -No ordering of elements
- -Hash collisions
- -Worst-case O(n) performance
System Design Applications:
Common Examples:
Graph
Collection of vertices connected by edges
Time Complexity
Space Complexity
O(V + E)Best Use Case:
When you need to represent relationships between entities
Advantages:
- +Flexible relationship modeling
- +Supports complex algorithms
- +Natural for network problems
Disadvantages:
- -Complex implementation
- -High space complexity
- -Difficult to optimize
System Design Applications:
Common Examples:
Bloom Filter
Space-efficient probabilistic data structure for membership testing
Time Complexity
Space Complexity
O(m)Best Use Case:
When you need memory-efficient approximate membership testing
Advantages:
- +Very space efficient
- +Constant time operations
- +No false negatives
Disadvantages:
- -False positives possible
- -No deletion support
- -No element retrieval
System Design Applications:
Common Examples:
Time Complexity Guide
Selection Guide: Choose data structures based on your most frequent operations. Prioritize O(1) and O(log n) complexities for critical paths. Consider space-time tradeoffs and real-world constraints like cache performance and implementation complexity.