A powerful start to mastering C++ STL with foundational concepts, properties, and real code.
📚 Week 1: STL I – Introduction to Containers & Adapters
🧠 1. Introduction
- What is an Algorithm?
- Step-by-step problem-solving method (like a recipe).
- Must be efficient, testable, and broken down into clear steps.
- What is a Data Structure (Container)?
- Efficient way to store, access, and modify large data collections.
- Enables memory optimization and quick processing.
- Components of Data Structures:
- Data values
- Relations
- Operations
- Constraints
- Components of C++ STL:
- 📦 Containers (Vectors, Stacks, etc.)
- 🧮 Algorithms (sort, find, etc.)
- ➰ Iterators (access/traverse data)
📦 2. Sequential Containers
🔹 Array
- Properties:
- Size: Fixed
- Random Access ✅
- Insert/Delete: ❌ (requires new array)
int arr[3] = {1, 2, 3};
cout << arr[1]; // 2
🔹 Vector
- Advantages:
- Dynamic size
- Efficient back insertion (amortized O(1))
- Maintains random access
- Properties:
Operation |
Time Complexity |
Random Access |
O(1) |
Insert Back |
O(1) |
Insert Middle/Front |
O(n) |
Erase Back |
O(1) |
Erase Middle/Front |
O(n) |
vector<int> v1; // empty
vector<int> v2(5); // [0,0,0,0,0]
vector<int> v3(5, 3); // [3,3,3,3,3]