CSC 378: Data Structures and Algorithm Analysis

ESTIMATING ASYMPTOTIC COMPLEXITY BY EXPERIMENT

Log/log graphs

We typically plot index1.gif , but it's sometimes useful to plot

index2.gif

in order to experimentally determine the asymptotic running time of an algorithm.

The idea is to run the algorithm with many different input sizes, index3.gif . For each run, the point index4.gif is plotted on a log/log graph. A line is drawn through the points. We'll see later how the slope and intercept of the line tell us the asymptotic running time.

In the log/log graph below, the running times are shown as red points and the blue line is is drawn through them. The points corresponding to larger index5.gif are given more importance when choosing the line, since it's with larger index6.gif that the dominant term of the running time is more evident.

The intercept is index7.gif and the slope is index8.gif . We'll use these later.

We will assume that the dominant term of the running time is of the form

index9.gif

(We will ignore lesser terms in the running time because the dominant term is the only one that affects the asymptotic behaviour of the algorithm.)

Finding c

On a log/log graph, the line index10.gif intersects the vertical axis at index11.gif . At the intercept,

index12.gif ,

so index13.gif and index14.gif is the intercept ( index15.gif on the graph above).

Finding k

On a log/log graph, the slope of the line index16.gif is

index17.gif

This is clear on the graph above, where the slope of the line is index18.gif . It's not index19.gif , which would be an almost flat line!

index20.gif

Thus the slope is equal to the exponent: index21.gif !

Summary

To experimentally determine the running time, plot index22.gif on a log/log graph. Draw a line through the points, giving greater weight to those corresponding to larger index23.gif . Let index24.gif be the line's intercept and index25.gif be the line's slope. Then, as index26.gif gets large, index27.gif is closely approximated by

index28.gif

and you've determined that the running time of the algorithm is (at least empirically) in index29.gif .

Example

On the graph above, index30.gif . So, as index31.gif gets large, the running time of the algorithm is approximately

index32.gif

Easy and useful!




Back to the lecture index

Copyright 1998     James Stewart