Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #20408

RE: name of a sorting algorithm

From Mel Wilson <mwilson@the-wire.com>
Newsgroups comp.lang.python
Subject RE: name of a sorting algorithm
Followup-To comp.lang.python
Date 2012-02-14 11:44 -0500
Organization Aioe.org NNTP Server
Message-ID <jhe31a$2ui$1@speranza.aioe.org> (permalink)
References <mailman.5800.1329231688.27778.python-list@python.org> <jhducq$kui$1@speranza.aioe.org> <mailman.5804.1329235868.27778.python-list@python.org>

Followups directed to: comp.lang.python

Show all headers | View raw


Prasad, Ramit wrote:

>> 
> for i in xrange (N-1):
>     for j in xrange (i, N):
>         if a[j] < a[i]:
>             a[i], a[j] = a[j], a[i]
>> It's what Wikipedia says a selection sort is: put the least element in
>> [0], the least of the remaining elements in [1], etc.
> 
> If your only requirement to match to selection sort is the end result,
> then every sort would be selection sort. If you meant "put the least
> element in [0] in the first pass" then that would indeed be selection
> sort, but that is not what the above code does. The above code is bubble
> sort.

Well, the classic bubble sort swaps adjacent elements until the extreme one 
gets all the way to the end.  This sort continually swaps with the end 
element during one pass until the end element holds the extreme.  Then it 
shrinks the range and swaps then next less extreme into the new end element.  
It does extra swaps because it combines the swap operation with recording 
the temporary extreme while it searches the subrange.

	Mel.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

name of a sorting algorithm Jabba Laci <jabba.laci@gmail.com> - 2012-02-14 16:01 +0100
  Re: name of a sorting algorithm Mel Wilson <mwilson@the-wire.com> - 2012-02-14 10:25 -0500
    RE: name of a sorting algorithm "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-02-14 15:50 +0000
      RE: name of a sorting algorithm Mel Wilson <mwilson@the-wire.com> - 2012-02-14 11:44 -0500
        RE: name of a sorting algorithm "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-02-14 20:21 +0000
        RE: name of a sorting algorithm "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-02-14 20:13 +0000
  Re: name of a sorting algorithm Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-02-14 16:33 +0100

csiph-web