Algorithms & Big-O Made Simple
An algorithm is just a recipe for solving a problem โ and Big-O is a simple way to talk about how fast it is as the data grows. Together they're how programmers reason about performance.
An algorithm is simply a step-by-step recipe for solving a problem - and different recipes for the same problem can be wildly different in speed. Big-O notation is programmers' shorthand for describing how an algorithm's time grows as the data grows. It sounds mathematical, but the core idea is simple and incredibly useful, and you can watch it happen with larzalgo.
Big-O: how does it scale?
Big-O ignores exact times and asks: as the input gets big, how does the work grow? A few common patterns cover most code.
| Big-O | Means | Example |
|---|---|---|
| O(1) constant | Same time regardless of size | Dict/set lookup |
| O(n) linear | Grows with the data | Scanning a list |
| O(log n) logarithmic | Grows very slowly | Binary search |
| O(n^2) quadratic | Grows fast - watch out | Nested loops over data |
The point isn't precise timing - it's the shape of growth. O(1) and O(log n) stay fast even for huge data; O(n) is fine; O(n^2) can become painfully slow as data grows, which is exactly what you learn to spot and avoid.
See it: search and sort
The classic example: finding an item. A linear scan is O(n) - double the data, double the work. Binary search (on sorted data) is O(log n) - it stays fast even as data explodes.
Reason about speed
- An algorithm is a recipe; different recipes for the same task vary hugely in speed.
- Big-O describes how work grows with data size - the shape, not the exact time.
- Watch for O(n^2) (nested loops over data) - it scales badly.
- Prefer O(1)/O(log n) where you can (dict lookups, binary search) - and watch algorithms run with larzalgo.
๐งฉ Do it with LarzOS
Turn this lesson into action with the exact free tools and AI workflows for the job:
๐ฏ Key takeaways
- An algorithm is a step-by-step recipe; different recipes for a task can differ enormously in speed.
- Big-O describes how an algorithm's work grows as the data grows - the shape of growth, not exact time.
- Common patterns: O(1) constant (dict lookup), O(log n) (binary search), O(n) (scan), O(n^2) (nested loops - beware).
- Prefer fast-scaling approaches (O(1)/O(log n)); watch algorithms run with larzalgo to feel the difference.
Frequently asked
Do I need to be good at maths to understand Big-O?
No - despite the notation, the core idea is conceptual, not mathematical. Big-O just answers 'as my data gets bigger, does the work grow slowly, proportionally, or explosively?' You mainly need to recognise a handful of patterns: constant (O(1)) means size doesn't matter; linear (O(n)) means work grows in step with the data; logarithmic (O(log n)) means it grows very slowly (like binary search halving the problem each step); and quadratic (O(n^2), often from a loop inside a loop) means it grows fast and can become slow on big data. You don't calculate precise formulas in day-to-day coding; you develop an intuition for these growth shapes and spot the expensive ones, especially nested loops. That intuition, not maths skill, is what makes you write code that stays fast.
How does this connect to the data structures from earlier?
Tightly - data structures and algorithms are two sides of reasoning about performance, which is why they're taught together. The structure you choose determines the Big-O of your operations: a dict/set gives O(1) lookups while a list gives O(n) - that speed difference IS the structure's algorithmic property. And algorithms often depend on structures: binary search's O(log n) speed requires sorted, indexable data (a list/array), and graph algorithms need a graph. So choosing the right structure often is choosing a better Big-O, and understanding Big-O tells you which structure to pick. Together they're the toolkit for writing code that stays fast as it scales - the core of this whole course, and a genuine mark of a capable programmer.
You've finished the Data Structures & Algorithms sessions
Now lock it in with the coursework.
Do the assignments โRelated lessons
Trees & Graphs: Modelling Relationships
Some data isn't a flat list โ it's connected. Trees (hierarchies) and graphs (networks) moโฆ
Data Structures & AlgorithmsWhy Data Structures Matter
How you store data decides how easy - and how fast - everything else becomes. Choosing theโฆ
Learn to Code (from Zero)What You Can Build & Where to Go Next
Once you can code, a world of building opens up - websites, apps, tools, automations, gameโฆ