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

  1. 17.1 Arrays, dynamic arrays and strings
  2. 17.2 Hash tables, sets and maps
  3. 17.3 Linked lists
  4. 17.4 Stacks, queues and deques
  5. 17.5 Trees and binary search trees
  6. 17.6 Heaps and priority queues
  7. 17.7 Tries, B-trees and specialized trees
  8. 17.8 Graphs: representation and traversal
  9. 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

  1. What is the time complexity of reading `arr[i]` from an array?

    1. O(1)
    2. O(log n)
    3. O(n²)
    4. 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.

  2. What is the average-case lookup time in a hash table, and the worst case?

    1. O(1) in every case, with no exceptions
    2. O(n) on average; O(1) in the worst case
    3. O(log n) on average and also in the worst case
    4. 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.

  3. What is the main advantage of a linked list over an array?

    1. Better CPU cache locality when iterating in order
    2. Less memory used per element stored in the list
    3. O(1) insert or remove at a known node, with no shifting
    4. 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.

  4. Which structure is LIFO (last in, first out)?

    1. A queue
    2. A heap
    3. A stack
    4. A hash table

    Answer: C. A stack Function calls use a call stack.

  5. What property does a binary search tree (BST) keep?

    1. Every node has exactly two children, with no exceptions
    2. The root node always holds the largest key in the tree
    3. Every level of the tree is completely filled with nodes
    4. 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.

  6. What is a binary heap mainly used for?

    1. Keeping sorted data for efficient range queries
    2. Fast O(1) lookup of any key, like a hash table
    3. Representing graphs as lists of adjacent nodes
    4. 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.

  7. What is a trie (prefix tree) good for?

    1. Finding the shortest paths between nodes in graphs
    2. Sorting large arrays of integers in linear time
    3. Storing key-value pairs whose keys are only integers
    4. 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.

  8. What are the two common ways to represent a graph?

    1. A binary heap of nodes and a trie of labels
    2. An adjacency list or an adjacency matrix
    3. A stack of nodes and a queue of edges
    4. 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.

  9. What is a union-find (disjoint set) structure used for?

    1. Storing arbitrary key-value pairs, like a hash map
    2. Tracking and merging groups, nearly O(1) per operation
    3. Sorting a list of strings in lexicographic order
    4. 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.

  10. What is the amortized cost of appending to a dynamic array (like `ArrayList`, `List<T>` or a Python list)?

    1. O(1) amortized, thanks to occasional doubling
    2. O(log n) for every append, from rebalancing
    3. O(1) in the worst case, for every single append
    4. 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).

Practice all 261 questions

More Server Side