AlgoScope

Best, Average and Worst Case

AnalysisbeginnerAsymptotic Notation

The same algorithm costs differently on different inputs; each case is a separate statement.

Decision · step 2 of 8Best, Average, Worst: Worst case: reversed
3002111721238435i

Before running: the best case is n - 1 = 5 comparisons, one per element. The worst is n(n - 1) / 2 = 15, when every element walks past everything before it. Which will this input be?

Open in the player →or start at step 2

What you will see

Run insertion sort on sorted, random and reversed input; count comparisons side by side.

How best, average, worst works →

Cost

SpaceO(1)

How you work with it here

play it through, compare two runs.

Screen readers: Growth curves are described in words and as a table of operation counts for sample input sizes; each concept has a one-sentence spoken definition.

Reduced motion: Curves and counters update without animation.

Before this

Leads to

Topics that need this one first.