On 4/14/06, Fred Cisin <cisin at xenosoft.com> wrote:
  On Fri, 14 Apr 2006, woodelf wrote:
  a.carlini at 
ntlworld.com wrote:
  I'm sure Knuth mentions
"random-sort" as being worse (randomly
 shuffle elements, check if order correct, if not then repeat). 
 Sounds like it
would have the smallest memory ( data and code)
 footprint around. 
 a bit larger than a bubble sort.
 But, at least it would tend to be slower. 
It's called bogosort.  It's O(N!) if your random number generator is perfect.
Pseudocode from the wikipedia entry:
---------------------------------------------------------------------
function bogosort(array)
   while not is_sorted(array)
     array := random_permutation(array)
---------------------------------------------------------------------
The only worse (speed wise) sorting algorithm that I know of is what I
call the infinitysort().  It just waits for random physical processes
to sort the array.  It is O((BN)!) where B is the size of the objects
in bits. pseudocode representation is...
---------------------------------------------------------------------
function infinitysort(array)
  while (not is_sorted(array)) or contains_different_elements(array)
    wait
---------------------------------------------------------------------
You could greatly improve this algorithm by changing wait to "generate
a random bit pattern the same size as array"
The fastest sort I know of is the O(1) sort called nosort().  It's pseudocode is
---------------------------------------------------------------------
function nosort(array)
---------------------------------------------------------------------
It's only problem is that its probability of getting the right answer
is equal to the probability that the array is already sorted.