PRACTICE • LEARN • GROW
Module 7 Final Quiz: The Standard Template Library (STL) MCQs
Solve topic-wise placement questions and improve your skills.
Module 7 Final Quiz: The Standard Template Library (STL) Progress
0 of 12 completed
0%
Topic Track
You are viewing MCQs in preview mode. Log in to select options, submit answers, and track your progress.
Log In to Answer
1
Which category of STL containers stores elements in strict sorted order by key using self-balancing trees?
A.
Sequence containers
B.
Associative containers (map, set)
C.
Unordered containers
D.
Container adaptors
Explanation & Key
Correct Answer:
2
What is the average time complexity of finding a key in std::unordered_map vs std::map?
A.
unordered_map is O(n); map is O(1)
B.
unordered_map is average O(1) via hashing; map is O(log n) via tree traversal
C.
Both are O(n)
D.
Both are O(1)
Explanation & Key
Correct Answer:
3
What does the .end() member function of an STL container return?
A.
An iterator pointing to the last valid element in the container
B.
An iterator pointing to the position one past the last element in the container
C.
A null pointer
D.
The total size of the container
Explanation & Key
Correct Answer:
4
What is the output of the following vector code?
vector v = {10, 20};
v.push_back(30);
v.pop_back();
cout << v.size();
A.
1
B.
2
C.
3
D.
20
Explanation & Key
Correct Answer:
5
What is the difference between vector::operator[] and vector::at()?
A.
operator[] is slower than at()
B.
operator[] performs no bounds checking for maximum speed; at() performs bounds checking and throws std::out_of_range if out of bounds
C.
at() can only be used with strings
D.
operator[] throws an exception on invalid index
Explanation & Key
Correct Answer:
6
What happens when you insert duplicate values into a std::set?
A.
The program throws a duplicate_error exception
B.
The duplicates are automatically discarded because std::set stores only unique elements
C.
The set replaces the old element
D.
The set converts to a vector
Explanation & Key
Correct Answer:
7
What algorithm from sorts a container in O(n log n) average time?
A.
std::bsearch
B.
std::sort
C.
std::arrange
D.
std::order
Explanation & Key
Correct Answer:
8
What does std::find(v.begin(), v.end(), target) return if the target element is NOT found?
A.
null
B.
-1
C.
v.end()
D.
0
Explanation & Key
Correct Answer:
9
Which STL container is best suited for frequent insertions and deletions at BOTH the front and back in O(1) time?
A.
std::vector
B.
std::deque (double-ended queue)
C.
std::array
D.
std::set
Explanation & Key
Correct Answer:
10
What is iterator invalidation in C++?
A.
An iterator being deleted by the garbage collector
B.
A condition where modifying a container (e.g. vector reallocating memory during push_back) renders existing iterators pointing to dead/moved memory
C.
Using an iterator on an empty container
D.
Passing an iterator to cout
Explanation & Key
Correct Answer:
11
What header must be included to use std::map and std::set?
A.
B.
C.
D.
Explanation & Key
Correct Answer:
12
What is the output of the following map code snippet?
map m;
m["apple"] = 5;
m["apple"] = 10;
cout << m["apple"];
A.
5
B.
10
C.
15
D.
Compilation Error
Explanation & Key
Correct Answer:
Question Palette
Answered
Current
Not Attempted
Wrong