Previous topic | Ada Home Page | Index

Sorting algorithms

There is nothing to choose between selection sort and bubblesort on the criteria of generality, effectiveness, termination. Elegance is in the eye of the beholder. The only criterion that might separate them is efficiency.

Although the two algorithms operate in very different ways, it turns out that they are similar in efficiency.

Selection sort

Comparisons Exchanges
best case N2 N-1
average case N2 N-1
worst case N2 N-1

Bubble sort

Comparisons Exchanges
best case N-1 0
average case N2 N2/2
worst case N2 N2/2

Both are O (N2)

The best sorting algorithms are O (N . log N)


Previous topic | Ada Home Page | Index
c-lokan@adfa.oz.au / 21 Feb 96