Quick sort algorithm, illustrated

You've done this instinctively: divided something that needed to be sorted - cards, for instance - into smaller groups, like suits, and then sorted so that each suit is in order. That operation is analogous to a computer algorithm, quick sort, which Wikepedia describes as:
Quicksort is a divide and conquer algorithm. Quicksort first divides a large list into two smaller sub-lists: the low elements and the high elements. Quicksort can then recursively sort the sub-lists.
The steps are:
  1. Pick an element, called a pivot, from the list.
  2. Reorder the list so that all elements with values less than the pivot come before the pivot, while all elements with values greater than the pivot come after it (equal values can go either way). After this partitioning, the pivot is in its final position. This is called the partition operation.
  3. Recursively apply the above steps to the sub-list of elements with smaller values and separately the sub-list of elements with greater values.
So what's the video? It's a very good illustration of the process. I found it yesterday via James Fallows' blog. Click the link for his gloss.

The same group also developed an illustration of a bubble sort - perhaps not as good an algorithm, but still a good dance.

No comments:

Popular Posts