Sort Comparisons

selection_sortThis entry implements a class to compare a couple (more to come in the next few days) sorting algorithms. The Java code is based on examples from the Algorithms fourth edition book by Robert Sedgewick and Kevin Wayne.

As you might already know, both Selection and Insertion sorts have a complexity of O(n^2). That said; in practice Insertion seems to be faster than Selection. If you take a look at the implementations, it is easy to insertion_sortdetermine that both algorithms use nested loops, but the number of cycles in the inner loops is dependent on the initial order of elements in the array for one of the sorts. Continue reading “Sort Comparisons”