1.When would you choose a linked list over a dynamic array, and what do you give up by doing so?
Warm-upWhat a strong answer covers
- Linked lists give O(1) insertion or deletion at a known node or at the ends without shifting elements, and grow without reallocation or amortized resize cost.
- Dynamic arrays give O(1) random access by index and far better cache locality because elements are contiguous, while linked lists require O(n) traversal to reach the k-th node.
- Call out the memory overhead of per-node pointers and the pointer chasing that causes cache misses, so in practice arrays often win even for insert-heavy workloads.
- Concrete fits: linked list for an LRU cache eviction list or a queue with frequent splicing; dynamic array for lookups, iteration, and binary search.
Where people lose the point
- Claiming linked-list insertion is O(1) without noting you first need an O(n) traversal to find the insertion point.
- Ignoring cache locality and asserting linked lists are faster for insert-heavy work when contiguous arrays usually outperform them in practice.
- Forgetting that dynamic array append is amortized O(1), not O(n), because of doubling.