Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Quoting the relevant portion from a now deleted blog post: <a href="http://corte.si/%2Fposts/code/timsort/index.html" rel="nofollow noreferrer">Visualising Sorting Algorithms: Python's timsort</a></p> <blockquote> <p>The business-end of timsort is a mergesort that operates on runs of pre-sorted elements. A minimum run length minrun is chosen to make sure the final merges are as balanced as possible - for 64 elements, minrun happens to be 32. Before the merges begin, a single pass is made through the data to detect pre-existing runs of sorted elements. Descending runs are handled by simply reversing them in place. If the resultant run length is less than minrun, it is boosted to minrun using insertion sort. On a shuffled array with no significant pre-existing runs, this process looks exactly like our guess above: pre-sorting blocks of minrun elements using insertion sort, before merging with merge sort.</p> </blockquote> <p>[...]</p> <ul> <li>timsort finds a descending run, and reverses the run in-place. This is done directly on the array of pointers, so seems "instant" from our vantage point.</li> <li>The run is now boosted to length minrun using insertion sort.</li> <li>No run is detected at the beginning of the next block, and insertion sort is used to sort the entire block. Note that the sorted elements at the bottom of this block are not treated specially - timsort doesn't detect runs that start in the middle of blocks being boosted to minrun.</li> <li>Finally, mergesort is used to merge the runs.</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload