A Simple Bubble Sort Function, glass houses

Bradley C. Kuszmaul bradley at godot.UUCP
Mon Jun 11 20:12:28 AEST 1984


Not nice to call someone an idiot, especially when you show your own ... er
... failure to keep up with the field.

The selection sort that you described is really no better than the bubble
sort under most conditions:
  bubble sort:  best time:  n steps
                worst time: n^2 steps
  selection sort: best time = worst time = 0.5*(n^2) steps
The selection sort is only better by a factor of two under the conditions
most favorable to it, and is sometimes worse by a factor of 0.5*n.  The
conditions under which bubble sort will win are when a file is "partly
sorted" already (i.e. the farthest a given element will have to travel
is small)

For good sorting algorithms, try quicksort (n^2 at worst n*log n at best,
with the "best" conditions much less restrictive than for bubble sort),
or something else.  (Quicksort and other sorting algorithms are discussed
in "Software Tools" by Kernighan and Plaugher (Excuse the spelling and possibly
incorrect name of the book) and "The Art of Computer Programming, vol II 
Sorting and Searching" by Knuth.

 --Bradley C. Kuszmaul
  {decvax!cca,ihnp4!mit-eddie,allegra!ias}!godot!bradley,
  "godot!bradley at mit-eddie"@MIT-XX.ARPA
-- 
  {decvax!cca,ihnp4!mit-eddie,allegra!ias}!godot!bradley,
  "godot!bradley at mit-eddie"@MIT-XX.ARPA



More information about the Comp.sources.unix mailing list