A sorting algorithm can be evaluated considering three main factors: time compexity, space complexity and stability.
An algorithm is stable when it doesn't reorder equal elements. This is required when sorting on multiple columns (i.g. ordering by date and then by name, without messing up the date order again)
The fastest sorting algorithms must run in time complexity O(n log n). Among those, quickSort is probably the fastest in most of the conditions and is very popular, but it's not stable. It's a space optimized version of a tree sort, that use recursion instead of a spatial tree.
mergeSort is usually slower then quickSort, but it's faster in nearly sorted lists and it's stable. It's the algorithm used in Collection.sort()
An other disadvantage is that mergeSort need to create a copy of the source collection, but it always guarantees a result in O(n log n). QuickSort doesn't guarantee this.
So, we can generally consider quickSort a little bit faster, but mergeSort more stable and predictable, therefore a better choice for a widely used library like the Collection Framework.
Copyright © 2013 Welcome to the website of Davis Fiore. All Rights Reserved.