Wednesday, 15 April 2015

Basic Sorting Algorithms (plus Python examples)

This site has animated visualizations of the main algorithms (h/t David R. Martin):
Sorting Algorithm Animations

The Sedgewick/Wayne book covers well (part of Coursera course):
Princeton: Sorting Applications

Quicksort is the fastest general-purpose sort.
In most practical situations, quicksort is the method of choice. If stability is important and space is available, mergesort might be best. In some performance-critical applications, the focus may be on just sorting numbers, so it is reasonable to avoid the costs of using references and sort primitive types instead.


Java's systems programmers have chosen to use quicksort (with 3-way partitioning) to implement the primitive-type methods, and mergesort for reference-type methods. The primary practical implications of these choices are to trade speed and memory usage (for primitive types) for stability and guaranteed performance (for reference types). 

The wiki entry is pretty comprehensive: http://en.wikipedia.org/wiki/Sorting_algorithm

Note also the basic sorting algorithms a la Python: http://danishmujeeb.com/blog/2014/01/basic-sorting-algorithms-implemented-in-python
 (Note, the same blogger has a good article on "jaavdoc" for Python: http://danishmujeeb.com/blog/2012/10/how-to-generate-javadoc-style-documentation-for-python)







Joshua Bloch 2006: Extra, Extra - Read All About It: Nearly All Binary Searches and Mergesorts are Broken 

No comments:

Post a Comment