« Back to full matrix

Animated Sorting Algorithm Demo: Nearly Sorted Initial Order

Size: 20 · 30 · 40 · 50 ·
Initial Condition: Random · Nearly Sorted · Reversed · Few Unique Keys

Discussion

Sorting nearly sorted data is quite common in practice. Some observations:

Insertion sort provides a O(n2) worst case algorithm that adapts to O(n) time when the data is nearly sorted. One would like an O(n·lg(n)) algorithm that adapts to this situation, but such an algorithm has not yet been discovered. Shell sort is the only sub-quadratic algorithm that is also adaptive in this case.

Directions

Key