AI engineering glossary · Data structures algorithms

What is timsort?

Timsort: A hybrid stable sorting algorithm that finds naturally ordered runs in the data, extends short ones with insertion sort and merges runs. It is O(n log n) worst case and close to O(n) on nearly sorted data, and it is the sort used by Python's sorted and list.sort.

Level: advancedTopic: Data structures algorithms

Timsort: an example

Sorting a log file that is already mostly in time order is very fast because Timsort detects the long ordered runs and merges few of them.

Related terms

More Data structures algorithms terms

Where you learn it

Timsort is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.