Re: Selection sort and bubble sort
On Oct 17, 4:41 am, user923005 <dcor...@connx.com> wrote:
> Of course, it's simply awful anyway. The only O(n^2) sort worth
> knowing is insertion sort. There are some very, very rare cases where
> selection or even bubble sort can prove worthwhile, but it takes a
> real expert to know what they are and even in that case, it carries
> intense danger (in case the initial conditions do not hold).
Insertion sort has the great advantage that it can be used to keep an
array sorted when new items arrive one at a time.
However, your command about bubble sort is incorrect. While selection
sort _always_ takes c*N^2 steps, bubble sort is very data dependent,
and there is one well-known situation where it is about the most
efficient method: Given an array with values a[i] = f (t, i) where f
changes slowly as t changes. Once that array is sorted, and t is
changed slightly, so that all the values in the array are close to
their correct position, bubblesort can be the fastest method to make
that array sorted again.
|