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


Groups > comp.lang.python > #20403 > unrolled thread

Re: name of a sorting algorithm

Started byDennis Lee Bieber <wlfraed@ix.netcom.com>
First post2012-02-14 10:31 -0500
Last post2012-02-14 10:31 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: name of a sorting algorithm Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-02-14 10:31 -0500

#20403 — Re: name of a sorting algorithm

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2012-02-14 10:31 -0500
SubjectRe: name of a sorting algorithm
Message-ID<mailman.5802.1329233507.27778.python-list@python.org>
On Tue, 14 Feb 2012 16:01:05 +0100, Jabba Laci <jabba.laci@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...

http://en.wikipedia.org/wiki/Bubble_sort

	As I recall, when I last had to code a simple sort for class
(1976-1980) I double-ended the algorithm so that I'd sweep both down and
up the list on each main loop. Probably didn't do anything to improve
the algorithm (unless I also added logic to track where the last swap
took place, and adjusted the outer loop end points to one place outside
of those swaps)

{Hmm, and I thought I was being clever back then:
http://en.wikipedia.org/wiki/Cocktail_sort }

>It's so simple that it's not mentioned anywhere. I guess it's called
>"selection sort" but I'm not sure. The minimum selection sort is an
>improvement of this one.

	It is NOT a "selection sort", which scans the data for the item that
is supposed to be "first" in the list, and swaps just that item. It then
scans again starting at the second place...

http://en.wikipedia.org/wiki/Selection_sort


	For the whole category of sorts:

http://en.wikipedia.org/wiki/Sorting_algorithm

{Or any DECENT textbook on data structures and algorithms should cover
at least: bubble, selection, insertion, quicksort, and heapsort -- oh,
and merge sort though that seems to have faded a bit [in my world, at
least] with the increase in computer memory sizes, b-tree/ISAM disk
files, etc. vs the use of multiple tape drives for sequentially accessed
data. [apparently merge sort has been revived for use in the Python
internal sort algorithm http://en.wikipedia.org/wiki/Timsort ]}
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web