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.

Play All
Play animation
Insertion
Play animation
Selection
Play animation
Bubble
Play animation
Shell
Play animation
Merge
Play animation
Heap
Play animation
Quick
Play animation
Quick3

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.