Model answer
Use an unordered_map from key to iterator for expected O(1) lookup and a doubly linked list for recency order. Access moves the node to the front; eviction removes the tail, both in O(1).
Use the key terms, then explain the reasoning.
The right structure follows from the dominant operations, ordering requirements, memory limits, input scale, and correctness constraints.
Data-structure selection begins with operations and guarantees, not names. List query types, update frequency, ordering needs, input scale, memory limits, concurrency, and acceptable worst-case behaviour.
Library structures encode trade-offs: vector favours locality and indexing; list favours known-position relinking; unordered_map favours expected lookup; map favours ordered logarithmic operations; priority_queue favours repeated extrema.
This is primarily a conceptual or selection topic. Use the linked implementation topics in this section to see the invariant expressed in C++.
Open a prompt when you are ready to check your answer.