×
WORKED EXAMPLEO(log n) vs O(n²)
big.mov
read the question
write what is given
pick the formula
method.md
show every
step
sticky.note
O(n)
maths.png
HELLO
my name is
doubtster
^ ω ^
{ ^_^ }
worked exampleCoding8 min read

Big O notation with a deck of cards

Find a card in a deck three ways and see why some methods stop working as the pile grows.

big-o-notation-deck-of-cards.md
In short

Big O describes how the work grows with the input. Halving each step is O(log n); comparing every pair is O(n²).

The card game

You want a card in a sorted deck. Checking from the top is O(n). Cutting the deck in half each time is O(log n). Comparing every card with every other is O(n²).

The numbers

ItemsO(log n)O(n²)
5262,704
1,000101,000,000

At 52 cards, both feel fine. At 1,000 the difference is enormous.

The common mistake

Try it: two nested loops over the same list of n items. What is the Big O? Answer: O(n²).

AI explanations can contain mistakes. Check important answers with your teacher.

AI explanations can contain mistakes. Check important answers with your teacher.

up-next.md

up next

Start here: how Doubtster works

Ask a question, read the answer, and turn it into a short explainer video when you want to see it worked out.

Previous: A simple weekly revision plan

more to read

see it worked out on screen

Chat is always free. Videos start with a $1.99 trial.