3.1.3 · D1Complexity Analysis

Foundations — Best, worst, average case — with examples

2,105 words10 min readBack to topic

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.


0. The starting picture: an algorithm as a machine that counts

Figure — Best, worst, average case — with examples

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.


1. — the size of the input


2. — one particular input


3. — the cost of one input


4. The three collectors: , , and the average

Now that we have a cost for each input, we squeeze the whole pile of inputs of size into three summary numbers.

Figure — Best, worst, average case — with examples

The figure lays out every size- input on a horizontal axis, each drawn at its height . Three markers pull out the story: the lowest dot (best), the highest dot (worst), and the balance point (average).

4a. — the smallest in a collection

4b. — the largest in a collection

4c. — the "size of" bars


5. Probability — how likely each input is

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.


6. and — the weighted average machine

Figure — Best, worst, average case — with examples

7. The Gauss sum — a tool the derivations lean on

The parent note keeps using one formula. Here's why that exact tool.

Figure — Best, worst, average case — with examples

8. , , — the "growth-rate" words (preview)


Prerequisite map

Input size n

One input instance I

Cost function T of I

min over inputs = Best

max over inputs = Worst

Probability Pr of I

Summation sigma

Expected value = Average

Gauss sum formula

Growth words Theta O Omega

Best Worst Average Case


Equipment checklist

Cover the right side and answer aloud. If any stalls, re-read that section before the parent note.

What does 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 and ?
is how big the input is; is one specific filled-in input of that size.
What does return?
A number — the count of basic operations the algorithm does on the exact input .
What do the bars in mean?
"The size of equals " — they restrict which inputs we look over.
picks out which case?
The best case — the lowest cost over all size- inputs.
picks out which case?
The worst case — the highest cost, a guarantee nothing is slower.
What is and what do all of them sum to?
The likelihood of receiving input ; over all size- inputs they sum to .
Write the average-case formula in words.
Add up, over every input, its cost times its probability: .
Why is average ?
The midpoint ignores probabilities; rare expensive inputs barely shift the true weighted balance.
What does equal and why does the topic use it?
; costs that grow like add up to this staircase sum.
Are the same thing as worst case?
No — they measure growth rate; best/worst/average measure which input. Independent axes.