CS3240: Data Structures and Algorithms

Introduction To Running Time

The exact running time of an algorithm is dependent on many factors including the input size, compiler, and the machine. The true time of an algorithm would have to be a function of all these factors:

In general, it is impractical to try including factors such as the compiler to calculate values for the time T. Instead, we find an integer value for T by considering the number of basic instructions executed before halting. Two approaches to finding T are calculating the worst case running time and the average case running time.

The worst case running time is the slowest possible time an algorithm may take. An algorithm is absolutely guaranteed to never exceed this:

Worst case:

The average running time is the time the algorithm will usually take. This type of analysis is best for evaluating applications such as editors and compilers where the programs are often called. In these cases, worst case inputs are rare, and the average time is more indicative of the algorithm's performance.

Average case:

© Lynne Grewe