Two simple ideas
- A data structure is a way of storing data so it is easy to use. A C++
vector,mapandsetare all data structures. - An algorithm is a list of clear steps that solves a problem, like a recipe.
Think of it like this: Think of a kitchen. The shelves, jars and drawers are data structures: they decide where things are kept. The recipe is the algorithm: the steps you follow to cook. A tidy kitchen (good data structure) makes the recipe (algorithm) quick to follow.
Why should I care?
With small inputs, any code is fast. With millions of items, the right choice can be the difference between one second and one hour. That's why DSA is the heart of coding interviews and competitive programming – and C++ is the most popular language for both.
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
vector<int> numbersList = {4, 8, 15, 16, 23, 42};
set<int> numbersSet = {4, 8, 15, 16, 23, 42};
// vector: check the items one by one
bool inList = find(numbersList.begin(), numbersList.end(), 23) != numbersList.end();
// set: jump almost straight to the answer
bool inSet = numbersSet.count(23) > 0;
cout << inList << " " << inSet << endl;
return 0;
}Output
1 1
Both say 1 (true), but for a million numbers the set is thousands of times faster. In this course you'll learn why, and how to choose.
What you'll learn
| Data structures | Algorithms |
|---|---|
| arrays and vectors, strings | searching (linear and binary search) |
| hash maps and sets | sorting (bubble, insertion, merge, quick) |
| linked lists, stacks, queues | recursion and backtracking |
| trees, binary search trees, heaps | graph algorithms (BFS, DFS, Dijkstra) |
| graphs | greedy algorithms and dynamic programming |
Tip: You need basic C++ for this course: variables,
if, loops, functions,cin/coutand a little aboutvectorandstruct. The challenges compile and run your C++ right in the browser.