Best, Average and Worst Case
The same algorithm costs differently on different inputs; each case is a separate statement.
Decision · step 2 of 8Best, Average, Worst: Worst case: reversed
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?
What you will see
Run insertion sort on sorted, random and reversed input; count comparisons side by side.
Cost
| Space | O(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.