Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site mit-eddie.UUCP
Path: utzoo!watmath!clyde!burl!mgnetp!ihnp4!mit-eddie!nessus
From: nessus@mit-eddie.UUCP (Doug Alan)
Newsgroups: net.lang
Subject: Re: A Simple Bubble Sort Function
Message-ID: <2126@mit-eddie.UUCP>
Date: Thu, 14-Jun-84 02:33:01 EDT
Article-I.D.: mit-eddi.2126
Posted: Thu Jun 14 02:33:01 1984
Date-Received: Fri, 15-Jun-84 00:37:32 EDT
References: <965@ihuxq.UUCP> <165@callan.UUCP> <131@godot.UUCP> <2096@mit-eddie.UUCP> <7471@umcp-cs.UUCP>
Organization: MIT, Cambridge, MA
Lines: 29

>	From: chris@umcp-cs.UUCP

>	If you are likely to have a completely (or nearly completely)
>	sorted list, use a Bubble Sort (or perhaps an insertion sort).
>	If you are likely to have a completely scrambled list, use a
>	quick sort.  If you have a list in which the items are usually
>	sorted but occasionally way out of place, you might try a Shell
>	sort.

Please, if you ever feel the urge to use a bubble sort, use a straight
insertion sort instead.  It's just as easy, and always faster.

About a quick sort being slow if the list to sort is ordered:  I suppose
you could always shuffle the list before sorting it.  That would only
take O(n) time (though it might be a bad O(n)).  Then you would be
almost guaranteed of the list being scrambled (unless you're unlucky).

Actually I like the "merge sort" the best.  It's so nice and clean and
recursive.  And it's always O(n*log(n)).  The algorithm for a merge sort
(in case you don't already know) is basically: Cut the list in half,
sort each half (recursively), and merge the two halves together.  See
how nice it is!
-- 
				-Doug Alan
				 mit-eddie!nessus
				 Nessus@MIT-MC

				"What does 'I' mean"?