[net.followup] A Simple Bubble Sort Function

geoff@callan.UUCP (06/09/84)

Jack Purdum is rapidly getting a reputation as an idiot with me.  I thought
that by now *EVERYBODY* knew that the bubble sort is for cretins.  If you
want a quick simple sort, write a "selection sort":  search 0 thru n for the
largest item and swap it with the item in slot n;  repeat with n=n-1 until
done.  This is exactly the effect that the bubble sort achieves (think about
it for a while if you aren't sure), but without all the unnecessary exchanges.

Moral:	Don't waste your effort optimizing the wrong solution to the problem.

	Geoff Kuenning
	Callan Data Systems
	...!ihnp4!wlbr!callan!geoff

mas@ecsvax.UUCP (06/11/84)

Wirth states, " ... in fact, the Bubblesort has hardly anything to
recommend it except its catchy name. "
page 68 of Algorithms + Data Structures = Programs .

...decvax!mcnc!ecsvax!mas

gsp@ulysses.UUCP (Gary Perlman) (06/12/84)

> Jack Purdum is rapidly getting a reputation as an idiot with me.  I thought
> that by now *EVERYBODY* knew that the bubble sort is for cretins.  If you
> want a quick simple sort, write a "selection sort":  search 0 thru n for the
> largest item and swap it with the item in slot n;  repeat with n=n-1 until
> done.  This is exactly the effect that the bubble sort achieves (think about
> it for a while if you aren't sure), but without all the unnecessary exchanges.

> Moral:	Don't waste your effort optimizing the wrong solution to the problem.

> 	Geoff Kuenning
> 	Callan Data Systems
> 	...!ihnp4!wlbr!callan!geoff

It is true that bubble sort is about as bad an algorithm as can be found.
Floor sort, used by me when I once dropped my FORTAN deck, is a bit worse.
Still, bubble sort is useful as a teaching tool, and its impracticality
makes it unlikely that teachers can find implementations of it in C.
I have trouble finding serious fault with anyone generous enough to
post their software to net.sources.  I realized that I was free to ignore it.
So while I can't cheer for the posting of some code that people should not use
for efficiency's sake, I find personal attacks in very poor taste.

For another non-optimal sorting routine, see the standard C text,
The C Programming Language (Prentice Hall) for a shell sort routine.
For small arrays, it gives remarkably good results for such a small procedure.
	Gary Perlman	BTL MH 5D-105	(201) 582-3624	ulysses!gsp

mickey@proper.UUCP (06/13/84)

>> Wirth states, " ... in fact, the Bubblesort has hardly anything to
>> recommend it except its catchy name. "
>> page 68 of Algorithms + Data Structures = Programs .
>> 
>> ...decvax!mcnc!ecsvax!mas
>> 

That statement actually came from Knuth. See page 111 of Volume 3 from
"The Art of Computer Programming".

I read somewhere, though i am sorry i can't give a reference, that 
bubble sort is quite efficient for N <= 10  (where N is the number of
records to be sorted).

M. Thompson

ags@pucc-i (06/17/84)

>  I read somewhere, though i am sorry i can't give a reference, that 
>  bubble sort is quite efficient for N <= 10  (where N is the number of
>  records to be sorted).

You could also say that BASIC is quite efficient for N <= 10 (where N is
the number of lines in the program).
-- 

Dave Seaman			"My hovercraft is full of eels."
..!pur-ee!pucc-i:ags

nessus@mit-eddie.UUCP (Doug Alan) (06/18/84)

>	From: mickey@proper.UUCP

>	I read somewhere, though i am sorry i can't give a reference,
>	that bubble sort is quite efficient for N <= 10 (where N is the
>	number of records to be sorted).

The bubble sort is efficient for N <= 10, but the straight insertion
sort, which is easier to do, is more efficient.
-- 
				-Doug Alan
				 mit-eddie!nessus
				 Nessus@MIT-MC

				"What does 'I' mean"?