name of a sorting algorithm
patentsvnc at gmail.com
Tue Feb 14 17:55:09 CET 2012
On Feb 14, 8:22 am, Arnaud Delobelle <arno... at gmail.com> wrote:
> On 14 February 2012 15:31, Dennis Lee Bieber <wlfr... at ix.netcom.com> wrote:
> > On Tue, 14 Feb 2012 16:01:05 +0100, Jabba Laci <jabba.l... at gmail.com>
> > wrote:
> >>Could someone please tell me what the following sorting algorithm is called?
> >>Let an array contain the elements a_1, a_2, ..., a_N. Then:
> >>for i = 1 to N-1:
> >> for j = i+1 to N:
> >> if a_j < a_i then swap(a_j, a_i)
> > Off hand... The ancient Bubble-Sort...
> No, it's not Bubble Sort. Bubble sort only swaps adjacent terms.
> I don't know what this sort is called, if it even has a name. It's a
> kind of Selection Sort, as each pass it looks for the minimum of the
> remaining unsorted items. But it ruffles the unsorted list each pass,
> seemingly to save using an extra register to store the current minumum
> (there was a time when registers were at a premium).
I disagree. In a bubble sort, one pointer points to the top element,
while another descents through all the other elements, swapping the
elements at the pointers when necessary. Then the one pointer moved
down to the next element and the process repeats. This looks like the
bubble sort to me. It was one of the first algorithms I had to
program in my first programming class in 1969.
More information about the Python-list