Bubble Sort is a sorting algorithm that is easy to understand: It makes as many rounds as there are items in the array; in each round, the values of two adjacent items in the array are compared. If the "left" value is larger than the "right" value, the items are swapped. In this manner, in each round the large values go upward, like air bubbles under water (this also why the algorithm bears this name). Despite its simplicity, this algorithm has some serious drawbacks, see the text below the applet.
Update 21.02.2008:
Perhaps surprisingly, also the american president Barack Obama knows the
disadvantages of Bubble Sort. For details, take a look at this.
Legend:
pink: greater value in current comparison
red: smaller value in current comparison
blue: the part that is already sorted
The running time of Bubble Sort very high compared to (almost) all other sorting algorithms1.
In Knuth's reference work "The Art of Computer Programming" [1] this algorithm is analyzed in detail.
The bottom line is that the only advantages of Bubble Sort are a sticky name and the fact
that the analysis of its running time leads to mathematically interesting questions [1, p. 110 and 140].
According to Knuth, the algorithm that is most easily implemented is
Update 10.12.2008: Many thanks go out to Tim Tempel who found a bug in the Java applet on this page. That bug is now fixed.
[1] D. E. Knuth. The Art of Computer Programming. Volume 3: Sorting and Searching, Second Edition. Addison-Wesley, 1997. ISBN 0-201-89685-0.
[2] Owen Astrachan. Bubble Sort: An Archaeological Algorithmic Analysis. 34th ACM Technical Symposium on Computer Science Education, 2003
[3] H. Gruber, M. Holzer und O. Ruepp): "Sorting the Slow Way: An Analysis of Perversely Awful Randomized Sorting Algorithms", 4th International Conference on Fun with Algorithms, 2007, Lecture Notes in Computer Science 4475, pp. 183-197