[Verse 1]
Python's sorting demon, hybrid beast unleashed
Galloping runs, insertion for the feast
Small arrays get tender loving care
Merge sort swoops when chaos fills the air
Adaptive mind reading patterns in your data
If it's sorted already, Timsort won't break ya
Seven elements trigger the insertion dance
Bigger than that gets the merge advance
[Chorus]
Tim-sort, Tim-sort, binary insertion climb
Galloping mode when one run's sublime
Merge stack watching, temp space allocated
Best of both worlds, complexity calculated
[Verse 2]
Hunt for runs, ascending or descending
Strictly decreasing gets reversed and mended
Minimum run size calculated with precision
Binary search guides each insertion decision
Gallop left and gallop right
When one pile dominates the fight
Seven consecutive wins unlock the speed
Exponential jumps fulfill the need
[Chorus]
Tim-sort, Tim-sort, binary insertion climb
Galloping mode when one run's sublime
Merge stack watching, temp space allocated
Best of both worlds, complexity calculated
[Bridge]
Stack invariants keep the balance tight
Merge at four ensures the height stays right
Worst case n log n guaranteed
Average case runs at lightning speed
[Verse 3]
Temporary buffer grows as data swells
Half the smaller run, the algorithm tells
Stable sorting keeps equivalent keys in place
Real world patterns, Timsort shows its grace
From CPython to Java's heart it spread
The sorting champion, enough said
[Outro]
Adaptive, stable, fast and clean
The smartest sorting algorithm seen
Tim Peters crafted this elegant machine
Timsort reigns supreme