Log inStart free
LESSON 3.13 · 5 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

Big-O and growth rates

Count the steps of three duplicate checks as the list grows.


Pro lesson. Stage 1 is free to watch. Pro opens all 5 stages, 3 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 3.13 · GROWTH BAYall pairs · n = 8 · T = 28 steps
01
Stage 1 of 5 · Count the steps
Time complexity counts steps as n grows. With no match, the worst case, all pairs takes 28 steps.
Explain it simply

You want to know if a list holds the same number twice. All pairs compares each item with every item after it. Each small square is one comparison, or one step. Count them: 28 steps for 8 items.

All pairs runs on 8 items. It takes 28 steps, one square per step, in 7 rows. It finds no match.

input itemstep, memory cell, c·g(n)real run, matchmore steps than all pairsindex or item on the diagonal
input · stepsgrowthnsteps T(n)040801202481216910831242883284175346827i = 07i = 16i = 25i = 34i = 43i = 52i = 6191832488281734T(8) = 7 + 6 + … + 1 = 8·7/2 = 28input · stepsgrowthnsteps T(n)040801202481216910831242883284175346827i = 07i = 16i = 25i = 34i = 43i = 52i = 6191832488281734T(8) = 7 + 6 + … + 1 = 8·7/2 = 28
Toy: 2 to 16 two-digit numbers · 3 duplicate checks · every step counted
STAGE 1 / 5
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
T(n)=steps of one run on n items\sy{T}{param}{T}(\sy{n}{data}{n}) = \text{steps of one run on } \sy{n}{data}{n} \text{ items}
T(8)=7+6+⋯+1=8⋅72=28T(8) = 7 + 6 + \dots + 1 = \tfrac{8\cdot 7}{2} = \sy{T}{param}{28}

T of n counts the steps of one run on n items.

Common mix-ups

MYTHA lower Big-O is faster at every input size.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01All pairs takes 28 steps for 8 items. About how many for 16 items?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 5
Unlock the full explainer
  • 4 more stages and 3 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.