Hire The World’s
Top Talent On Demand

Toptal connects the top 3% of freelance developers all over the world.

Reversed Initial Order

Animation, code, analysis, and discussion of 8 sorting algorithms on reversed initial order.

How to use: Press “Play all”, or choose the button for the individual row/column to animate.

InsertionSelectionBubbleShell
Insertion on Reversed Initial Order
Selection on Reversed Initial Order
Bubble on Reversed Initial Order
Shell on Reversed Initial Order
MergeHeapQuickQuick3
Merge on Reversed Initial Order
Heap on Reversed Initial Order
Quick on Reversed Initial Order
Quick3 on Reversed Initial Order

DISCUSSION

Sorting an array that is initially in reverse sorted order is an interesting case because it is common in practice and it brings out worse-case behavior for insertion sort, bubble sort, and shell sort.

KEY

  • Black values are sorted.
  • Gray values are unsorted.
  • A red triangle marks the algorithm position.
  • Dark gray values denote the current interval (shell, merge, quick).
  • A pair of red triangles marks the left and right pointers (quick).

Preparing for a technical interview? Check out our interview guides.