DSA Lab

Quick sort visualizer

Pick a pivot, move smaller items to its left and the rest to its right (partition), then sort both sides the same way. The usual fastest general-purpose sort in practice. Pick the pivot at random to avoid the O(n²) case.

Quick sort: its cost, and how to use this tool

Time: best O(n log n), average O(n log n), worst O(n²). Extra memory: O(log n) stack. Not stable, in place.

Sort a ready-made input or your own numbers. The bars are the array; the code beside them (in Python, C, C++ or Java) marks the line that just ran, and every step is explained and worked out below the bars.

Lessons that use it

  • Quick sort (Algorithms)Partition around a pivot, sort each side recursively; O(n log n) on average, O(n²) when the pivots are bad.
  • Divide and conquer and the master theorem (Algorithms)Split a problem into smaller copies of itself, solve them recursively, combine the answers, and work out the running time with the master theorem.

See also