Let a, b, c, and d denote constants
In order of dominance (top is most dominant). Realize that algorithms of higher dominance are bad!
Function |
condition |
common name |
Nn |
|
|
N! |
|
N factorial |
an |
dominates bn if a > b |
exponential |
Nc |
dominates Nd if c > d |
polynomial (cubic, quadratic, etc.) |
n log n |
|
n log n |
n |
|
linear |
log n |
|
logarithmic (regardless of base) |
1 |
|
constant |
Linear |
logarithmic |
n*log2N |
quadratic |
cubic |
exponential |
exponential |
factorial |
1 |
0 |
0 |
1 |
1 |
2 |
3 |
1 |
2 |
1 |
2 |
4 |
8 |
4 |
9 |
2 |
4 |
2 |
8 |
16 |
64 |
16 |
81 |
24 |
8 |
3 |
24 |
64 |
512 |
256 |
6561 |
40320 |
16 |
4 |
64 |
256 |
4096 |
65,536 |
43,046,721 |
2.09E+013 |
32 |
5 |
160 |
1024 |
322,768 |
4,294,967,296 |
…1.85E+15 |
2.63E+035 |
64 |
6 |
384 |
4096 |
262,144 |
1.84E+17 |
…3.43E+30 |
1.27E+089 |
128 |
7 |
896 |
16,384 |
2,097,152 |
3.4E+38 |
…1.18E+61 |
3.86E+215 |
256 |
8 |
2048 |
65,536 |
1,677,216 |
1.16E+77 ??? |
…1.39E+122 |
Find other calculator |
Note 1: The value here is approximately the number of machine instructions executed by a 1 gigaflop computer in 5000 years, or 5 years on a current supercomputer (teraflop computer)
Note 2: The value here is about 500 billion times the age of the universe in nanoseconds, assuming a universe age of 20 billion years.log2n |
n |
nlog2n |
n2 |
2n |
|
Current Computers |
N1 |
N2 |
N3 |
N4 |
N5 |
Ten times faster |
N1 x 30 |
N2 x 10 |
N3 x 3 |
N4 x 3 |
N5 + 3 |
Thousand times faster |
N1 x 9,000 |
N2 x 1,000 |
N3 x 111 |
N4 x 31 |
N5 + 10 |
Million times faster |
N1 x 19E+6 |
N2 x 1E+6 |
N3 x 5,360 |
N4 x 1,000 |
N5 + 20 |
array int sorta; // this comes from somewhere in a messy state
int temp; // for the swap
int outIx, inIx; // these are indecies
// outer loop over the sorted array -- when everything's sorted we're done
for (outIx gets the values sorta.length down to 1) {
// from the beginning of the list to the end of the unsorted bit
for(inIx = 1; inIx < outIx-1; inIx++) {
// If adjacent items are out of order, swap them!
if (sorta[inIx-1]>sorta[inIx]) {
temp = sorta[inIx-1];
sorta[inIx-1] = sorta[inIx];
sorta[inIx] = temp;
}
}