Skip to content

Data structures and algorithms · Sorting

Sorting

Put things in order yourself, once. · 12 minutes

In real code you will call sorted() and move on. Write a sort yourself once anyway: it is the clearest place to see an algorithm's cost change with its input, and to see the difference between changing a list and building a new one.

Predict first

Insertion sort slides each item left past bigger ones. On which input does it do the least work?