Skip to content

Commit 70d5702

Browse files
committed
docs
1 parent 3de148f commit 70d5702

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

Objects/listsort.txt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -836,15 +836,21 @@ So cutting the number of compares is almost always measurably helpful in
836836
CPython, and the savings swamp the quadratic-time data movement costs for
837837
reasonable minrun values.
838838

839-
Additionally, "binary insertion sort" has implemented adaptivity procedure,
840-
which reduces the number of comparisons for cases where data is already
841-
sorted to high degree in either forward or reversed order.
842-
While "binary insertion sort" ensures optimal number of comparisons
843-
it looses best case of textbook insertion sort when data is highly sorted
844-
in correct order. Adaptivity addition brings that back and more at small cost.
845-
It adapts to any data where position of next element is close to the one of
846-
last element. Thus, it adapts to cases where it is highly sorted in correct
839+
Additionally, "binary insertion sort" has implemented adaptivity procedure.
840+
While "binary insertion sort" ensures optimal number of comparisons,
841+
it looses best case of "textbook insertion sort" when data is highly sorted
842+
in correct order. Adaptivity brings that back (and more) at a small cost.
843+
It adapts to any data where position of the next element is close to the one of
844+
the last. Thus, it adapts to cases where it is highly sorted in correct
847845
order, reverse order or elements are being funneled into some mid-point.
846+
For example, it adapts well to sequence [-4, 4, -3, 3, -2, 2, -1, 1],
847+
for which it only does ~2n comparisons. It needs to compare twice for
848+
each element as being in the middle it needs to compare with elements at
849+
both sides.
850+
Also, it is worth noting that driftless random walk is the threshold
851+
beyond which adaptivity starts paying off. Thus, in practice, adaptivity
852+
has little effect when sorting raw stock prices, where drift value is
853+
very small in comparison to fluctuations around it.
848854

849855

850856
LEFT OR RIGHT

0 commit comments

Comments
 (0)