because it selects the smallest element and then adds it to the end of the output.
it is relatively simple to implement.
However as sorting algorithms go, it is rather inefficient.
However if you had a very large data set it would be quite slow.
So are there other approaches?
In fact, there are dozens of sorting algorithms.
implement in code, but slow.
Selection sort is one such algorithm, as are bubble sort and insertion sort.
Their running time is quadratic in the input size.
the algorithm will take four times as long to run.
Examples of such algorithms include quick sort, merge sort and others.
is a variation of merge sort called tim sort.
The runtime for these algorithms is close to linear.
If it were linear, doubling the input size would only take twice as long.
are very close to linear.
For the simple and slow approach, the runtime grows quadratically.
So these are called n squared sorts.
Both selection and bubble sort are n squared sorts.
They have the same general shape, and the algorithms are easy to understand.
two of these n squared sorts, taken from sorttimings.java.
20,000 strings, taking two and four seconds respectively.
large lists, the other category of sorting algorithms is much much better.
even more elements, to understand why n squared sorts, are called inefficient.
This graph shows that n squared sorts from 10,000 to 70,000 strings.
the number of elements being sorted is on the x axis.
How long would it take to sort many, many more elements?
to extrapolate the sorting for a million, or a billion elements.
So how big a difference is there?
To sort a million strings would require 6.4 hours with bubble sort.
Tim sort function requires less than one second to sort the same million strings.
To sort a billion elements would require 738 years with bubble sort.
see that it takes fewer than 20 minutes to sort a billion strings.
as part of their standard library.
that programmers can get the most use out of it.
For example, you want to sort earthquakes.
when he wrote that sort?
certainly he was not thinking about the particular earthquake class you wrote.
You saw these already as a way to write generic code.
An interface is a type that promises certain methods.
call the method it promises.
pass them to the sorting library.
comparator, which you will learn about shortly.
It is what you should use any time you need to sort data.