📦 Phase 4 · STL 🟣 Checkpoint Quiz MODULE 19 · QUIZ

STL Quiz

⏱️ 20 min
📖 Recap + Assessment
🧩 12 Quiz Questions
🏆 Phase Checkpoint
Your progress in Phase 4100%
🎯 What this checkpoint covers: This is a review lesson, not new teaching. It's a 12-question assessment pulling from everything in Phase 4 — Lessons 15 through 18: vector/list/deque, map/set/unordered containers, stack/queue/priority_queue, and the <algorithm> header. Skim the recap below, then take the quiz.

Phase 4 in a Nutshell

Before the quiz, here's a compressed recap of the four lessons you've completed. If any of these points feel unfamiliar, it's worth a quick re-read of that lesson before you continue.

1
Lesson 15 — Vector, List & Deque
vector is a contiguous, resizable array with O(1) random access via [] and amortized O(1) push_back(). list is a doubly-linked list — O(1) insertion/removal anywhere via an iterator, but no random access. deque supports O(1) push/pop at both ends while still allowing [] access.
2
Lesson 16 — Map, Set & Unordered Containers
map<K,V> stores unique key-value pairs automatically sorted by key, with O(log n) operations (it's a balanced tree internally). set is the same idea for keys alone. unordered_map/unordered_set use hashing instead of a tree — average O(1) lookup, but no ordering guarantee.
3
Lesson 17 — Stack, Queue & Priority Queue
stack is LIFO — push(), pop(), top(). queue is FIFO — push(), pop(), front(), back(). priority_queue always keeps the largest element accessible via top() by default (a max-heap), regardless of insertion order.
4
Lesson 18 — Algorithms
The <algorithm> header provides sort() (optionally with a comparator), find() (O(n), works unsorted), binary_search() (O(log n), requires a sorted range first), and max_element()/min_element()/reverse() — all operating on iterator ranges, so the same functions work across container types.
Picking the right container is the real skill
The STL isn't about memorizing syntax — it's about matching a container's underlying structure to what your program actually needs to do. Need indexed access? vector. Need fast middle-insertion? list. Need sorted unique keys? map. Need "always give me the biggest one"? priority_queue. This quiz checks that instinct, not just the method names.

One Program, Four Containers + Algorithms

A short program touching a vector, a map, a priority_queue, and <algorithm>'s sort() and find() — all in one place.

quick_reference.cpp
C++
// quick_reference.cpp
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;

int main() {
    // vector — resizable array
    vector<int> scores = {72, 95, 88, 61};
    sort(scores.begin(), scores.end());   // ascending, in place

    // find() on the now-sorted vector
    auto it = find(scores.begin(), scores.end(), 88);
    if (it != scores.end()) {
        cout << "Found 88 in the sorted list" << endl;
    }

    // map — sorted unique key-value pairs
    map<string, int> nameToScore;
    nameToScore["Ada"] = 95;
    nameToScore["Grace"] = 88;

    // priority_queue — top() is always the largest
    priority_queue<int> pq;
    for (int s : scores) pq.push(s);
    cout << "Top score: " << pq.top() << endl;

    return 0;
}
⚠️
Trap this quiz loves to test
binary_search() silently gives wrong answers on an unsorted range — it doesn't throw an error, it just returns garbage. Always confirm your data is sorted before reaching for it, or use plain find() instead.
🧩 STL Checkpoint — 12 Questions
Answer all 12 questions to test your mastery of Phase 4. Instant feedback on every answer.
1. Which STL container provides O(1) random access via operator[] and stores its elements contiguously in memory, like a resizable array?
2. Which container is best suited for frequent insertions and removals in the middle via an iterator, when you don't need random access?
3. What is the key structural advantage of std::deque over std::vector?
4. Which container stores unique key-value pairs automatically sorted by key?
5. What is the main tradeoff of std::unordered_map compared to std::map?
6. In std::stack, which pair of operations views and removes the most recently added element?
7. What ordering does std::queue follow?
8. By default, what does .top() return on a std::priority_queue<int>?
9. Which header must you include to use std::sort, std::find, and std::binary_search?
10. What must be true about a range BEFORE you call binary_search() on it?
11. What does std::find() return if the target element is NOT found in the range?
12. How do you sort a vector<int> in DESCENDING order using the STL?
Finished the checkpoint?
Mark it complete to track your progress.
🎉

Phase 4 Complete!

You've mastered the Standard Template Library — containers and algorithms alike. Phase 5 starts with templates, the mechanism that makes the STL itself possible.

Module 19 of 26 Phase 4 — STL