The whole topic rests on ONE idea: for inputs of the same size n , an algorithm's cost can still change depending on how the input is arranged. So instead of one number, we describe cost with three honest answers — the luckiest input (best), the unluckiest (worst), and the typical one (average).
Before you can read the parent note comfortably, you need to own every symbol it throws at you. Below, each symbol appears in the order that lets the next one make sense. Nothing is used before it is built.
Think of an algorithm as a little machine. You feed it an input (a list, a number, a name to find). It does some steps and stops. We want to measure "how much work" — but work depends on what you feed in.
The picture shows two lists of the same length going into the same machine. One comes out after 1 step, the other after 8. Same size — different work. That single observation is why we need three cases. Hold onto it.
n = input size
n is a plain counting number (1 , 2 , 3 , … ) telling us how big the input is. For a list, n is how many items it holds. For searching a name in a phone book, n is how many names there are.
Picture a row of n boxes lined up. The row can be short (n small) or long (n large). Everything we measure is measured for one fixed row length — we freeze n , then ask what happens.
Why the topic needs it: cost naturally grows with size. If we didn't fix n , we couldn't tell whether slowness came from a big input or an unlucky one. Fixing n separates those two causes.
Common mistake The number one confusion
"Bigger n = worst case." No. Worst case is measured at a single n . You change the arrangement of the n items, not their count. See the parent note for the full steel-man.
I = an input instance
I is one specific filled-in input: not "a list of length 8" but "this exact list [3,7,1,9,2,8,4,6]". Two inputs can share the same size n yet be different instances I .
If n is "row of 8 boxes", then I is "the 8 boxes filled with these specific contents". Change what's inside → new I , same n .
Why the topic needs it: best/worst/average are about comparing different I 's that all have size n . Without a name for "one particular input", we couldn't say "the least work over all inputs" precisely.
T ( I ) = operation count on input I
T ( I ) is a number: how many basic operations the algorithm performs when you feed it the specific input I . A "basic operation" is the one repeated step we choose to count (a comparison, a swap, a multiply).
T is a function — feed it an input, it returns a count. Picture a turnstile that clicks once per basic operation; T ( I ) is the final number on the counter after input I finishes.
Why we count only ONE kind of operation: a program does many little things per step, but they all grow together. Counting the dominant one (the comparison inside the loop) captures the growth without drowning in detail.
T ( I )
For linear search on [9,4,7] looking for 7: we compare 9? (no), 4? (no), 7? (yes) → stop. So T ( I ) = 3 comparisons for that input.
Now that we have a cost T ( I ) for each input, we squeeze the whole pile of inputs of size n into three summary numbers .
The figure lays out every size-n input on a horizontal axis, each drawn at its height T ( I ) . Three markers pull out the story: the lowest dot (best), the highest dot (worst), and the balance point (average).
min ∣ I ∣ = n T ( I )
Read as: "the minimum value of T ( I ) , taken over all inputs I whose size equals n ." The little |I| = n underneath means "only look at inputs of size n ".
Line up all the T -values as dot heights (the figure above). min points at the lowest dot. It answers: of every possible size-n input, which one lets the algorithm finish with the fewest operations? That is the best case , written B ( n ) .
max ∣ I ∣ = n T ( I )
"The maximum of T ( I ) over all size-n inputs." Same pile of dots, but now point at the highest one. That's the worst case , W ( n ) .
Worst case is a guarantee : no size-n input can be slower than W ( n ) . It's the promise "I will never take longer than this."
∣ I ∣ = n
The vertical bars around I mean "the size of" . So ∣ I ∣ = n says "the size of input I is n ". (Same bars you'd use for length of a list.)
Why the topic needs it: it's the leash that keeps min and max from wandering onto inputs of the wrong size.
The average needs a new idea the min/max didn't: not all inputs are equally common. To average fairly, we must weight each input by how often it shows up.
Pr ( I ) = probability of input I
Pr ( I ) is a number between 0 and 1 saying how likely it is that the input you actually receive is exactly I . All the Pr ( I ) over all size-n inputs add up to 1 (something must happen).
Imagine a bag holding one ticket per possible input, but fatter inputs get more tickets . Pr ( I ) is the fraction of tickets that say "I ". If every arrangement is equally likely and there are n of them, each gets Pr ( I ) = n 1 .
Why the topic needs it: the average case is only meaningful once you decide how likely each input is . Change the assumed likelihoods → change the average. See Expected Value and Probability Distributions .
∑ = "add up all of these"
The Greek capital sigma ∑ is shorthand for repeated addition . ∑ i = 0 n − 1 ( stuff i ) means "let i run from 0 to n − 1 , plug each into stuff , and total the results."
∑ is a for-loop that adds. total = 0; for i in range(...): total += stuff(i). The symbol under ∑ is the loop's start, the symbol on top is the end.
E [ T ( I ) ] = expected value = the average
The expected value is the probability-weighted average of the cost:
A ( n ) = E I [ T ( I ) ] = ∑ I Pr ( I ) T ( I )
Read it as: for each input I , multiply its cost by its probability , then add all those products.
The figure shows why weighting matters. Two inputs cost 2 and 10 . If both are equally likely, the average sits at the midpoint 6 . But if the cheap one is far more common (fat bar), the balance point slides toward the cheap side — nowhere near the midpoint. That is exactly why "average = (best + worst)/2" is wrong: rare expensive inputs barely tug the balance. This is the seed of the Quicksort average-case surprise.
Common mistake Why not just
2 best + worst ?
Because the midpoint ignores Pr ( I ) — it pretends both extremes are equally likely. Average respects how rare or common each input is. They only accidentally match when the distribution is symmetric.
The parent note keeps using one formula. Here's why that exact tool .
Why this tool and not another? In linear search and insertion sort, the cost of input number i is proportional to i . Adding those costs up literally is 1 + 2 + … . So we need a closed form for that staircase sum — and Gauss's pairing gives it instantly.
The picture proof: stack bars of heights 1 , 2 , … , n into a staircase. Take a second copy , flip it upside down, and slot it on top. Every column now has the same height n + 1 , and there are n columns → the doubled area is n ( n + 1 ) . So one staircase is half of that: 2 n ( n + 1 ) . That's why the formula has a ÷ 2 .
Worked example Quick check,
n = 4
1 + 2 + 3 + 4 = 10 , and 2 4 ⋅ 5 = 10 . ✓
Definition Growth notation
Θ ( f ( n )) , O ( f ( n )) , Ω ( f ( n )) are labels for how fast a count grows as n gets large, ignoring constant factors and small terms. O = "grows no faster than ", Ω = "grows at least as fast as ", Θ = "grows exactly like ".
Think of them as speed-limit signs on the count. They don't care whether T = 3 n or T = 100 n — both are Θ ( n ) , because doubling n doubles the cost either way.
Why the topic needs it, and the key warning: these signs describe growth ; best/worst/average describe which input . They are two independent axes. You can say "best case is Θ ( n ) " and "worst case is Θ ( n 2 ) ". Full treatment lives in Asymptotic Notation (Big-O, Omega, Theta) — that's your next stop after this page.
Growth words Theta O Omega
Cover the right side and answer aloud. If any stalls, re-read that section before the parent note.
What does n stand for, and what stays true about it across all three cases? The input size ; it is held fixed — only the arrangement varies.
What is the difference between n and I ? n is how big the input is; I is one specific filled-in input of that size.
What does T ( I ) return? A number — the count of basic operations the algorithm does on the exact input I .
What do the bars in ∣ I ∣ = n mean? "The size of I equals n " — they restrict which inputs we look over.
min ∣ I ∣ = n T ( I ) picks out which case?The best case B ( n ) — the lowest cost over all size-n inputs.
max ∣ I ∣ = n T ( I ) picks out which case?The worst case W ( n ) — the highest cost, a guarantee nothing is slower.
What is Pr ( I ) and what do all of them sum to? The likelihood of receiving input I ; over all size-n inputs they sum to 1 .
Write the average-case formula in words. Add up, over every input, its cost times its probability: ∑ I Pr ( I ) T ( I ) .
Why is average = ( best + worst ) /2 ? The midpoint ignores probabilities; rare expensive inputs barely shift the true weighted balance.
What does ∑ k = 1 n k equal and why does the topic use it? 2 n ( n + 1 ) ; costs that grow like i add up to this staircase sum.
Are Θ/ O /Ω the same thing as worst case? No — they measure growth rate ; best/worst/average measure which input . Independent axes.