Quicksort runs in:
O(n^{2}) time in the worst case O(n log_{2} n) time in the average caseQuicksort is a bit different than merge sort. Quicksort has good constant factors and is good in practice. It has a big advantage over merge sort in that it works inplace. It will do the sorting in the original array and a copy need not be created.
To sort a subarray A[p..r]:
So why must neither side of the partition have all the elements?? There are a couple of reasons:
In class, I put up on the board the list of numbers: 8 10 7 2 5 9 4 3. And I chose the first element as the pivot. What we ended up with was the list 3 1 4 5 2 : 7 10 9 8 6, where the colon separates the two parts of the partition. The partition is not always so even. When it is very unbalanced, quicksort ends up taking more time than merge sort.
Let's go through some of the analysis that was done in class by looking at worst, best and average cases for quicksort. We must note though that in all the cases, to partition n elements it takes time O(n).
The worst case in quicksort occurs when the partition gives a 1 : n1 split every time. Graphically, this looks like:

The best case occurs when we have an even split all the time. The tree looks exactly like the recursion tree that we got for merge sort:

For the average case, I will use the graceful art of handwaving. Let's just say that most splits are not too far from even. Given this, the analysis exceeds the scope of this course, but it turns out to be O(n log_{2} n).
There are many ways in which we can choose the pivot point to almost guarantee us that our splits are not so bad. In Homework #6, we will explore how to choose the pivot point in a different way. Rather than always choosing A[p], we will choose 3 values from the array at random, and we will use the one with the middle value as the pivot by first swapping it with A[p] and then doing what we normally do to carry out quicksort. So consider this a teaser for homework #6 and maybe you will get pumped up for it!
Data structures by definition are ways to organize information, or data, in the computer to facilitate accessing and operating on it. However, a word of caution: It is not always obvious to what is the best way to organize that data. Here is an example of a data structure that we have seen:

A linked list is a data structure in which the elements are arranged in a linear order determined by following a chain of links. Here is an example of a linked list of goalie names (you were expecting names of wingers?):
