Algorithms: Design and Analysis Videos
List of resources related to Algorithm Design and Analysis:
List of resources related to Algorithm Design and Analysis:
Some notes on IntroSort…
Introsort or introspective sort is a hybrid sorting algorithm that provides both fast average performance and (asymptotically) optimal worstcase performance. It begins with quicksort and switches to heapsort when the recursion depth exceeds a level based on (the logarithm of) the number of elements being sorted. This combines the good parts of both algorithms, with practical performance comparable to quicksort on typical data sets and worstcase O(n log n) runtime due to the heap sort. Since both algorithms it uses are comparison sorts, it too is a comparison sort.
Introsort was invented by David Musser in Musser (1997), in which he also introduced introselect, a hybrid selection algorithm based on quickselect (a variant of quicksort), which falls back to median of medians and thus provides worstcase linear complexity, which is optimal. Both algorithms were introduced with the purpose of providing generic algorithms for the C++ Standard Library which had both fast average performance and optimal worstcase performance, thus allowing the performance requirements to be tightened.
Source: Wikipedia  David Musser Paper ‘Musser (1997)’
In the Microsoft .NET Framework 4.5, an Introsort implementation is used instead of simple QuickSort.
If the sort is not successfully completed, the results are undefined. This method uses the introspective sort (introsort) algorithm as follows:
1


This implementation performs an unstable sort; that is, if two elements are equal, their order might not be preserved. In contrast, a stable sort preserves the order of elements that are equal.
For arrays that are sorted by using the Heapsort and Quicksort algorithms, in the worst case, this method is an O(_{n} log _{n}) operation, where _{n} is the Length of array.
You can view the full source for .NET 4.5 sorting implementation here: .NET 4.5.1 QuickSort
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 

You can view the latest (MIT licensed) Mono implemention on Github: Mono.C5 Sorting.cs
Quicksort, also known as partitionexchange sort, uses these steps.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 

1 2 3 4 5 6 7 8 9 10 11 

1 2 3 4 5 6 7 8 9 

1 2 3 4 5 6 

You start with an unordered sequence. You create N empty queues. You loop over every item to be sorted. On each loop iteration, you look at the last element in the key. You move that item into the end of the queue which corresponds to that element. When you are finished looping you concatenate all the queues together into another sequence. You then reapply the procedure described but look at the second last element in the key. You keep doing this until you have looped over every key. When you complete this process the resulting sequence will be sorted as described above.
Let n_{i} be the number of items in the sequence to be sorted. N is number of integers that each key element can take. Let n_{k} be the number of keys in each item.
The total time to sort the sequence is thus O(n_{k}(n_{i} + N)).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 
