Data structures for coding interviews – Server Side interview prep
261 interview-style multiple-choice questions on Data structures for coding interviews, organized by topic: concepts, scenarios, code to read and tradeoffs, each with a short explanation. Learn the 56 key terms with the flashcards first, then test yourself.
Take the practice test · Flashcards · All study tools
What it covers
- 17.1 Arrays, dynamic arrays and strings
- 17.2 Hash tables, sets and maps
- 17.3 Linked lists
- 17.4 Stacks, queues and deques
- 17.5 Trees and binary search trees
- 17.6 Heaps and priority queues
- 17.7 Tries, B-trees and specialized trees
- 17.8 Graphs: representation and traversal
- 17.9 Union-find, Bloom filters, LRU caches and other advanced structures
Key terms
17.1 Arrays, dynamic arrays and strings
- Dynamic array
- Resizable array with amortized O(1) append
- Hash table
- Key-value structure with average O(1) operations
- Collision
- Two keys hashing to the same bucket
- Load factor
- Ratio of entries to buckets
- Amortized O(1)
- Average cost per operation over many
- Row-major order
- Rows stored contiguously in memory
- Bitset
- Compact array of boolean bits
- Sliding window
- A moving range over contiguous data
17.2 Hash tables, sets and maps
- Chaining
- Colliding keys share a bucket list
- Open addressing
- Colliding keys probe for another slot
- Hash flooding
- Attack using deliberate collisions
- Perfect hash
- No collisions for a known key set
17.3 Linked lists
- Singly linked list
- Nodes with a `next` pointer
- Doubly linked list
- Nodes with `next` and `prev`
- Sentinel node
- A dummy node that simplifies edge cases
- Fast and slow pointers
- Pointers moving at different speeds
- Circular list
- Last node links to the first
17.4 Stacks, queues and deques
- Linked list
- Nodes connected by pointers
- Stack
- LIFO collection
- Queue
- FIFO collection
- Deque
- Double-ended queue
- Monotonic stack
- A stack kept in sorted order
- Ring buffer
- Fixed array with wrapping indexes
- Backpressure
- Slowing producers when a queue is full
17.5 Trees and binary search trees
- Binary search tree
- Tree with ordered left and right subtrees
- Balanced tree
- Tree kept to O(log n) height
- Heap
- Tree-based priority queue
- Trie
- Prefix tree for strings
- In-order traversal
- Left, node, right
- Self-balancing tree
- Keeps height O(log n) with rotations
- Complete binary tree
- Levels full, last filled from the left
- Tree diameter
- Longest path between two nodes
17.6 Heaps and priority queues
- Binary heap
- A complete tree with the heap property
- Priority queue
- Removes items by priority, not arrival
- Sift up / sift down
- Restoring heap order after a change
- Two-heap median
- Max-heap of lows, min-heap of highs
- Lazy deletion
- Skipping stale entries when popped
17.7 Tries, B-trees and specialized trees
- Radix tree
- A trie with merged single-child chains
- B+ tree
- Values in linked leaves
- LSM tree
- Write-optimized sorted runs with compaction
- Segment tree
- Range queries with updates
- Skip list
- Leveled linked lists for fast search
- Merkle tree
- Tree of hashes for verification
17.8 Graphs: representation and traversal
- Adjacency list
- Graph stored as neighbor lists
- BFS
- Breadth-first search
- Union-find
- Disjoint set structure for grouping
- Bloom filter
- Probabilistic membership structure
- Topological sort
- Order of a DAG with edges pointing forward
- Bellman-Ford
- Shortest paths with negative edges
- Minimum spanning tree
- Cheapest edges connecting all nodes
- Strongly connected component
- Nodes all reachable from each other
- Bipartite graph
- Nodes split into two sides with edges only across
17.9 Union-find, Bloom filters, LRU caches and other advanced structures
- Count-Min Sketch
- Approximate stream frequencies
- HyperLogLog
- Approximate distinct counts
- Reservoir sampling
- Uniform sample from a stream
- LFU cache
- Evicts the least frequently used
Sample practice questions
What is the time complexity of reading `arr[i]` from an array?
- O(1)
- O(log n)
- O(n²)
- O(n)
Answer: A. O(1) The element's address is computed directly from the base address plus `i` times the element size, so no scanning is needed.
What is the average-case lookup time in a hash table, and the worst case?
- O(1) in every case, with no exceptions
- O(n) on average; O(1) in the worst case
- O(log n) on average and also in the worst case
- O(1) average; O(n) worst, with many collisions
Answer: D. O(1) average; O(n) worst, with many collisions Good hash functions and resizing keep chains short.
What is the main advantage of a linked list over an array?
- Better CPU cache locality when iterating in order
- Less memory used per element stored in the list
- O(1) insert or remove at a known node, with no shifting
- O(1) access to any element directly by its index
Answer: C. O(1) insert or remove at a known node, with no shifting Arrays win on indexing and cache performance.
Which structure is LIFO (last in, first out)?
- A queue
- A heap
- A stack
- A hash table
Answer: C. A stack Function calls use a call stack.
What property does a binary search tree (BST) keep?
- Every node has exactly two children, with no exceptions
- The root node always holds the largest key in the tree
- Every level of the tree is completely filled with nodes
- Left subtree keys are smaller, right subtree keys larger
Answer: D. Left subtree keys are smaller, right subtree keys larger An in-order traversal visits keys in sorted order.
What is a binary heap mainly used for?
- Keeping sorted data for efficient range queries
- Fast O(1) lookup of any key, like a hash table
- Representing graphs as lists of adjacent nodes
- A priority queue: O(1) peek, O(log n) insert and remove
Answer: D. A priority queue: O(1) peek, O(log n) insert and remove It's stored compactly in an array.
What is a trie (prefix tree) good for?
- Finding the shortest paths between nodes in graphs
- Sorting large arrays of integers in linear time
- Storing key-value pairs whose keys are only integers
- Fast prefix lookups like autocomplete, in word-length time
Answer: D. Fast prefix lookups like autocomplete, in word-length time Each edge represents one character.
What are the two common ways to represent a graph?
- A binary heap of nodes and a trie of labels
- An adjacency list or an adjacency matrix
- A stack of nodes and a queue of edges
- A singly linked list of edges, and nothing else
Answer: B. An adjacency list or an adjacency matrix Lists suit sparse graphs; matrices suit dense ones.
What is a union-find (disjoint set) structure used for?
- Storing arbitrary key-value pairs, like a hash map
- Tracking and merging groups, nearly O(1) per operation
- Sorting a list of strings in lexicographic order
- Finding the maximum element in a changing collection
Answer: B. Tracking and merging groups, nearly O(1) per operation Used in Kruskal's algorithm and connectivity problems.
What is the amortized cost of appending to a dynamic array (like `ArrayList`, `List<T>` or a Python list)?
- O(1) amortized, thanks to occasional doubling
- O(log n) for every append, from rebalancing
- O(1) in the worst case, for every single append
- O(n) for every append, from copying the array
Answer: A. O(1) amortized, thanks to occasional doubling When the array is full it grows (often doubling) and copies, which costs O(n) once in a while; spread over all appends, that averages to O(1). An individual append can still be O(n).
More Server Side
- HTTP fundamentals
- REST API design
- GraphQL
- gRPC & real-time APIs
- OAuth 2.0, OIDC & JWT
- Sessions, cookies & web app security
- C# & .NET
- Java & Spring Boot
- Node.js & Express
- Python, Django & FastAPI
- Go (Golang)
- Concurrency & multithreading
- OOP & SOLID
- Design patterns
- Dependency injection
- Logging & observability
- Algorithms & Big-O
- Linux & shell scripting