CP2001 Data Structures and Algorithms
Sorting

Page 2 of 2

prev
Back
up
Start

Summary of Sorting Algorithms

Chpt 18

Experiments on randomly generated arrays of floating-point numbers using different sorting algorithms were compiled for different array sizes. Each sorting experiment was undertaken 100 times and the average time lapse (in ticks - 1/60th of a second) recorded.

These average-case performances are shown in the following graph [Standish]:

[Note: Be careful when using these results for your application - remember that these are average-case results using randomly generated data values].


Run-time complexities for the different sorting algorithms can be summarised as follows:

Sort Algorithm Average-case Best-case Worst-case Extra Memory Required?
Insertion sort O(N^2) O(N) O(N^2) No
Selection sort O(N^2) O(N^2) O(N^2) No
Heap sort O(N log N) O(N log N) O(N log N) No
Merge sort O(N log N) O(N log N) O(N log N) Yes
Quick sort O(N log N) O(N log N) O(N^2) No


Selecting Sorting Algorithms

We have given a brief outline of the run-time performances (best-case, average-case and worst-case) of the different sorting algorithms. We have also considered their usage of memory.

Many other efficient sorting algorithms, each with advantages/disadvantages:

Moral of the Story!

Under most circumstances, it may not be crucial which sorting algorithm you choose - assuming you think about the pitfalls of each algorithm and how these might be relevant to your application.

There are two morals of the story:

  1. If you absolutely need to select the best sorting algorithm, use measurement and tuning on YOUR application data to discover it.

  2. Under different circumstances, different sorting algorithms will be the best.

There is no single best sorting algorithm that beats all the others all of the time.


Copyright © 1998 Olivier de Vel. All rights reserved.
prev
Back
up
Start