๐Ÿงฎ
๐Ÿงฎ Data Structures & Algorithms ยท DS-101 ยท Session 6 of 6

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.

โฑ 9 min read๐Ÿ“… Updated 2026-07-27๐Ÿ“Š Tables, charts & examples

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.

๐Ÿ“Œ Worked example
Twenty steps, not a million. To find a name in a sorted list of a million, a linear scan might check up to a million entries. Binary search - repeatedly halving the search range - finds it in about twenty checks, because each step throws away half of what's left. Same goal, sorted the same way, but O(log n) versus O(n) is the difference between roughly twenty operations and a million. It's the clearest illustration of why the algorithm you choose, not just faster hardware, is what makes code scale.

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-OMeansExample
O(1) constantSame time regardless of sizeDict/set lookup
O(n) linearGrows with the dataScanning a list
O(log n) logarithmicGrows very slowlyBinary search
O(n^2) quadraticGrows fast - watch outNested 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.

Comparisons to find an item in a list of 1,000,000Linear scan O(n)~1,000,000Binary search O(log n)~20Illustrative but real: on a million items, a linear scan may check a million; binary search checks about twenty. Same task, vastly different scaling - which is why the algorithm you choose matters as much as the data structure.

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.

๐ŸŽ“ Final session complete

You've finished the Data Structures & Algorithms sessions

Now lock it in with the coursework.

Do the assignments โ†’

Related lessons

More in this course

Course home → · Browse all courses →