# quickSort

5

documenting my process. I keep pulling the blue pixels out by mistake.

A visualization of the quicksort algorithm.

wise

image21_10_19

2

coastline_005 & expo_006

Quick-sort with Hungarian folk dance

image21_44_56

why is quick sort n log n?

haha life is a sad place when i resort to asking tumblr for hw qs :3

XKCD did it again.

Jobinterview-Quicksort is hilarious.

So is StackSort (Image alt-Text): Connect to Stackoverflow, search for “Sort a list” and run code snippets until the list is sorted.

I HAVE FOUND THE WONDERFUL PART OF YOUTUBE AGAIN

petunia

8

At the Funeral Home

2

lost in that ol’ iostream again

Hungarian dancers shows the sorting algorithms

image21_35_51

Divide-and-Conquer Algorithms: QuickSort

What is QuickSort?

An efficient algorithm based on a Divide-and-Conquer principle for solving a problem efficiently. It is usually the algorithm of choice in most situations as it consumes relatively fewer resources during execution, and not too difficult to implement.

How does QuickSort work?

• Divide the given array into two non-empty sub-arrays A[p…q] and A[q+1…r] such that every key in A[p…q] is less than or equal to every key in A[q+1…r].
• Recursively, sort the two sub-arrays by calling Quicksort.
• Conquer and combine all the results from all subproblems to merge them into one solution for the given problem.

1. In-place sorting, uses small stack.
2. Takes nlogn time to sort n items on average.
3. Short inner loop.

1. Depends on recursion, therefore when recursion is not available, the implementation tends to become a lot more complicated.
2. Requires a quadratic time in the worst-case O(n^2).

Best Case Analysis:

Best Case situation is when QuickSort divides the array exactly in half. In other words, the best to be a median of the keys in A[p…r] every time partitioning is done.

Recurrence relation in this case is:

T(n) = T(n/2) + T(n/2) + O(n)

T(n) = 2T(n/2) + O(n)

T(n) = O(nlogn)

Worst Case Analysis:

Worst Case situation is when QuickSort is called on an already sorted array A[1…n]. The algorithm will partition the array into two unequal sizes (one large subarray yet to be divided recursively many times, and another small subarray possibly of size 1).

Therefore the running time will be proportional to:

T(n) = n + (n - 1) + (n - 2) + (n - 3) + … + 2

T(n) = [ (n + 2) ( n - 1) ] / 2

T(n) = O(n^2)

trying to port my pixel sorting script from processing to ofx. Getting close, but some data leakage has occurred.

I just used mergesort to sort a collection of real world items. Granted, it was 80 receipts in COMPLETE messed up order. But still. I’m such a CS nerd.

Next time I’ll use quicksort and compare the speeds.

image21_42_15