DSA combines data structures (ways to store and access data) and algorithms (step-by-step procedures). The goal is correct answers with predictable time and memory use as input size grows.
Data structures
- Array / vector — contiguous storage, O(1) index access
- Stack / queue — restricted access order (LIFO / FIFO)
- Hash map / set — average O(1) lookup by key
- Tree / heap / graph — hierarchical or networked relationships
Algorithms
- Searching — linear scan, binary search on sorted data
- Sorting — comparison sorts, when O(n log n) matters
- Traversal — BFS/DFS on trees and graphs
- Optimization patterns — greedy, dynamic programming, divide and conquer
Tiny example: sum an array
#include
int main() {
int arr[] = {3, 1, 4, 1, 5};
int sum = 0;
for (int x : arr) sum += x;
std::cout << "sum = " << sum << "\n";
return 0;
}
Important interview questions and answers
- Q: Structure vs algorithm?
A: A structure organizes data; an algorithm operates on it—often analyzed together for complexity. - Q: Why study DSA for jobs?
A: Technical interviews and performance-sensitive backends test classic patterns and Big-O reasoning.
Self-check
- Name four data structures from this lesson.
- What does O(1) index access mean for arrays?
Tip: Separate structure (how data is stored) from algorithm (how you process it) in interview answers.
Interview prep
- DSA definition?
Data structures organize data; algorithms solve problems on them with analyzable cost.
- Array access?
Contiguous storage gives O(1) index access.