Two simple ideas
- A data structure is a way of storing data so it is easy to use. A Python list, a dictionary and a set are 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?
Small programs work fine however you write them. But when there is a lot of data – millions of users, songs or products – a smart choice can be the difference between one second and one hour.
Here is a tiny example. Both pieces of code check if a number is in a collection:
numbers_list = [4, 8, 15, 16, 23, 42]
numbers_set = {4, 8, 15, 16, 23, 42}
print(23 in numbers_list) # Python checks the items one by one
print(23 in numbers_set) # Python jumps straight to the answerOutput
True True
Both print True, but for a million numbers the set is thousands of times faster. In this course you'll learn why, and how to pick the right tool.
What you'll learn
| Data structures | Algorithms |
|---|---|
| lists (arrays), strings | searching (linear and binary search) |
| dictionaries and sets (hashing) | 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 only need basic Python for this course: variables, if, loops, lists, dictionaries and functions. If any of those feel shaky, have a quick look at our Learn Python tutorial first.