Containers and Algorithms
CONCEPTS:C++ Containers and Algorithms
Question Variations
- "When should you choose `vector`, `list`, or `deque`?"
- "How do `map` and `unordered_map` differ?"
- "Why use `std::find_if` or `std::ranges` algorithms?"
- "What operations invalidate vector iterators?"
Why This Is Asked
The standard library is a major part of idiomatic C++. Interviewers use this question to assess whether you choose data structures by access pattern and use expressive algorithms instead of error-prone hand-written loops where a standard operation already exists.
Key Concepts
std::vectoris a contiguous dynamic array and is often the default sequence container.std::unordered_mapoffers average constant-time lookup;std::mapmaintains ordered keys.- Algorithms accept iterator ranges and work across compatible containers.
- Iterator invalidation depends on the container and operation.
Question Variations
- “When should you choose
vector,list, ordeque?” - “How do
mapandunordered_mapdiffer?” - “Why use
std::find_iforstd::rangesalgorithms?” - “What operations invalidate vector iterators?”