Loading [MathJax]/extensions/tex2jax.js
Fast Sta­ble Sort­ing, Adapt­ing to Ex­ist­ing Runs
J. Ian Munro
Uni­ver­sity of Wa­ter­loo

Sort­ing is prob­a­bly the most heav­ily stud­ied task in com­put­ing. It is often re­quired that the method be sta­ble (i.e. records with equal keys are kept in their orig­i­nal order). It is also highly de­sir­able that a method take ad­van­tage of al­ready sorted seg­ments of the input. Tim­sort is a well known pro­ce­dure in both Python and Or­a­cle’s Java li­brary for just this prob­lem. While ef­fec­tive in prac­tice, it has been hard to prove that it is an O(n lg n) tech­nique and in­deed ver­sions of the method have been both in­cor­rect for some in­puts. This led us to ex­plore other meth­ods for the same prob­lem and we pre­sent two sta­ble merge­sort vari­ants, “peek­sort” and “pow­er­sort”, both of which ex­ploit ex­ist­ing runs and find nearly op­ti­mal merg­ing or­ders with neg­li­gi­ble over­head. We demon­strate that our meth­ods are com­pet­i­tive in terms of run­ning time with state-of-the-art im­ple­men­ta­tions of sta­ble sort­ing meth­ods.

This is joint work with Se­bas­t­ian Wild.