Programming Fundamentals · Algorithms Behind AI

Big-O: See at a Glance How Long Code Will Run

Drag the data-size slider and watch O(1), O(log n), O(n), and O(n²) diverge; 10× the data—who barely flinches, who blows up on the spot

THE QUESTION THIS PAGE ANSWERS

ANSWER FIRST

What is the key idea behind “Big-O: See at a Glance How Long Code Will Run”?

Drag the data-size slider and watch O(1), O(log n), O(n), and O(n²) diverge; 10× the data—who barely flinches, who blows up on the spot

DECISION RULE

Make the claim earn its place. Use this page as a decision aid, not a definition to memorize. Connect the idea to one real task, one observable result, and one failure that would change your mind.

TRY NEXT

Write one question you could answer with evidence after trying this idea.

WATCH FOR

A conclusion that sounds complete but leaves the key assumption untested.

Interactive 1 · Four curves diverge

Time curves for four common “playbooks”: O(1) gray (one step no matter how much data), O(log n) green (cut in half each time), O(n) blue (walk through one by one), O(n²) red (everyone compared with everyone). Drag the slider from 10 to 100,000; the right side converts to real time at “100 million ops/sec.” Watch: early on, all four lines pile together—when data is small every algorithm looks fast, which is exactly why demos lie.

100
Drag all the way left first, then slowly right. Below n = 100, all four lines hug the floor—that's “everything fine in the demo stage.” Past 10k, the red line takes off; at 100k, O(n²) already needs 100 seconds, while the green line is still near zero.
Interactive 2 · What if data grows 10×

A more direct question: your boss says “users will 10×”—how much slower does each playbook get? Hit “×10,” click three times and watch the gap snowball.

Current data size 1,000 items
Remember this pattern first: when data ×10, O(1) stays put, O(log n) only +a bit, O(n) also ×10, O(n²) jumps ×100. Click the button a few times to check.
Interactive 3 · Guess this code

You've got the ruler—time to try it. Three snippets of pseudocode; pick a complexity for each. Trick: don't read every line—just ask “when data grows, how much more work does it do?”

Why this ruler helps you? When you review AI-written code later, you don't need to understand every line—just ask: “What's the complexity here? Can it still run at 100,000 rows?” The AI will tell you straight. And most “got slower and slower after launch” incidents turn out to be one O(n²) hiding in a corner. Next lesson we look at the most famous O(n²) inside LLMs—the attention mechanism.

The algorithmic cost curve in “Interactive 1 · Four curves diverge”

“Time curves for four common “playbooks”: O(1) gray (one step no matter how much data), O(log n) green (cut in half each time), O(n) blue (walk through one by one), O(n²) red (every…” is not asking you to memorize steps. It trains you to spot repeated work: as the input grows, how many comparisons, moves, or recursive calls does the program perform?

Find repeated work before declaring something fast

Break “A more direct question: your boss says “users will 10×”—how much slower does each playbook get?” into three questions: how input size changes, what each round does, and whether the next round can shrink its search space. Big-O describes growth, not an exact time on every machine; constants, memory, and data distribution still matter.

  • Big-O only tracks the trend : it doesn't care how fast one run is—only how time grows as data grows
  • Constants don't matter; trends kill : 2× slower is fine; growing with n² is a death sentence
  • Small data hides the gap : four curves pile together in the demo stage; the explosion waits until data grows

Theoretical optimum is not always practical optimum

When AI writes an algorithm, trace a small input by hand and benchmark progressively larger inputs. That turns “You've got the ruler—time to try it.” from a slogan into a performance claim you can check.

From “Interactive 1 · Four curves diverge” to “Interactive 2 · What if data grows 10×”

“Interactive 1 · Four curves diverge” grounds the problem in “Time curves for four common “playbooks”: O(1) gray (one step no matter how much data), O(log n) green (cut in half each time), O(n) blue (walk through one by one), O(n²) red (everyone compared with everyone). D…”. “Interactive 2 · What if data grows 10×” then moves it toward “A more direct question: your boss says “users will 10×”—how much slower does each playbook get? Hit “×10,” click three times and watch the gap snowball”. Together, they show that the lesson is not just a conclusion to remember, but a claim with conditions.

Carry the judgment into the next situation

For a real task, find the repeated work first, ask how input size changes, and use a small benchmark to verify the theoretical judgment. Complexity should not become a label detached from the situation.

  • “Interactive 1 · Four curves diverge”: Time curves for four common “playbooks”: O(1) gray (one step no matter how much data), O(log n) green (cut in half each time), O(n) blue (walk through one by one), O(n²) red (everyone compared with everyone). D…
  • “Interactive 2 · What if data grows 10×”: A more direct question: your boss says “users will 10×”—how much slower does each playbook get? Hit “×10,” click three times and watch the gap snowball
  • “The closing point”: n² causes most lag accidents : when reviewing code, hunt nested loops first

The final “The closing point” brings the discussion to “n² causes most lag accidents : when reviewing code, hunt nested loops first”. The useful thing to carry forward is knowing which judgments must be revisited when input, scale, or risk changes.

What this lesson wants to share

  • Big-O only tracks the trend: it doesn't care how fast one run is—only how time grows as data grows
  • Constants don't matter; trends kill: 2× slower is fine; growing with n² is a death sentence
  • Small data hides the gap: four curves pile together in the demo stage; the explosion waits until data grows
  • n² causes most lag accidents: when reviewing code, hunt nested loops first
Mark as learned Your reading progress updates automatically
← PreviousNext →

Keep reading

The next useful article in the thread.

ARTICLE DISCUSSION

Leave one useful thought here.

Keep the idea that clicked, the question that stayed open, or a small note for the next learner.

Discussing Big-O: See at a Glance How Long Code Will Run Algorithms Behind AI
3discussionsArticle discussion · synced with the Circle
View in the learning circle
AM
Asha MorganContent editor
INSIGHTField note

I turned one judgment from this article into a small experiment I could run today. Knowing what to observe next is more useful than simply remembering the conclusion.

ARTICLE DISCUSSION7 helpful
LH
Lin HarperIndie developer
INSIGHTInsight

After reading this, I first looked for the conditions behind the idea instead of copying the method into a project. That order made the later trade-offs much clearer.

ARTICLE DISCUSSION5 helpful
KM
Kiki MooreProduct operations
QUESTIONQuestion

When this judgment reaches real work, which constraint should be added first? I am curious which step matters most between reading and the first practical attempt.

ARTICLE DISCUSSION4 helpful