C++ Quick Syntax Reference Sheet & Standard Library Algorithmic Complexity

This quick reference cheat sheet provides a rapid lookup guide to modern C++ syntax, keywords, standard library containers, and mathematical time complexities.

STL Container Time Complexity Matrix

Container Data Structure Random Access [] Front Insert/Delete Back Insert/Delete Search Complexity
std::vector Contiguous Array $O(1)$ $O(N)$ $O(1)$ Amortized $O(N)$ linear / $O(log N)$ sorted
std::deque Chunked Buffers $O(1)$ $O(1)$ $O(1)$ $O(N)$
std::list Doubly Linked List $O(N)$ (No []) $O(1)$ $O(1)$ $O(N)$
std::set / map Red-Black Tree $O(log N)$ (map only) $O(log N)$ $O(log N)$ $O(log N)$ Guaranteed
std::unordered_map Hash Table $O(1)$ Average $O(1)$ Average $O(1)$ Average $O(1)$ Average ($O(N)$ worst)
std::stack Adapter (Deque) Not supported Not supported $O(1)$ Push/Pop $O(1)$ Top only
std::priority_queue Binary Max/Min Heap Not supported Not supported $O(log N)$ Push/Pop $O(1)$ Top element

Essential Modern C++ Syntax Snippets

// Smart Pointers
auto uPtr = std::make_unique<MyClass>(arg);   // Unique ownership (no copy)
auto sPtr = std::make_shared<MyClass>(arg);   // Shared ownership (ref count)

// Range-based for loop
for (const auto& item : container) { ... }    // Zero copy read-only

// Structured Bindings (C++17)
auto [key, value] = *mapIterator;

// Lambdas
auto isPositive = [](int x) { return x > 0; };

// Concepts (C++20)
template <std::integral T>
T gcd(T a, T b);

Frequently Asked Questions (FAQ) - Student & Interview Review

Q1. What is the best way to revise C++ before an exam or interview?

Bookmark this reference sheet! Review the STL container time complexity matrix, the 4 OOP pillars, smart pointer semantics, and the 4-stage compilation pipeline.

Q2. What is the Big-O complexity of searching in std::unordered_map vs std::map?

std::unordered_map provides average O(1) constant time lookups using hash buckets. std::map provides guaranteed O(log N) logarithmic time lookups using balanced Red-Black trees.

Explore Related C++ Tutorials & Next Steps

Boost your C++ proficiency by studying these closely connected core modules:

C++ Tutorial Home

Return to the comprehensive tutorial homepage.

50+ Practice Programs

Practical implementation exercises.

100+ Interview Q&A

Top placement questions and answers.

Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Stumbleupon Share on Tumblr Share on Reddit Share on Diggit

You may also like this!