Examples of Algorithm Speed

Let's say we have two algorithms. We input n numbers to each of them, and the result pops out at different times depending on which algorithm we're using.

The first algorithm (Algorithm A) runs in 3(nnn) time, or n-cubed time. Thus, if we enter 10 numbers, it will take 3(10)(10)(10) = 3000 instructions to run through the algorithm.

The second algorithm (Algorithm B) runs in 19,500,000n time, or linear time. If we enter 10 numbers into B, it will take 195,000,000 instructions to execute the algorithm.

OK, let's assume Algorithm A is running on a Cray-1 supercomputer (programmed in Fortran), and Algorithm B is running on an old TRS-80 (programmed in BASIC).

n
Cray-1 Fortran
3(nnn) nanoseconds
TRS-80 BASIC
19,500,000n nanoseconds
10
.000003 seconds
.2 seconds
100
.003 seconds
2 seconds
1,000
3 seconds
20 seconds
2,500
50 seconds
50 seconds
10,000
49 minutes
3.2 minutes
1,000,000
95 years
5.4 hours
Cray-1 is a trademark of Cray Research, Inc.
TRS-80 is a trademark of Tandy Corporation.

If that doesn't convince you, how about this?

Time
33n
46n lg n
13(nn)
3.4(nnn)
n=10
.00033 seconds
.0015 seconds
.0013 seconds
.0034 seconds
n=1,000
.033 seconds
.45 seconds
13 seconds
.94 hours
n=100,000 3.3 seconds 1.3 minutes 1.5 days 108 years

The Intro to Visual Basic homepage is hosted by GeoCities