a.) 12 | b.) 22 | c.) 32 | d.) 42 | e.) 52 | f.) 102 | g.) 1002 |
1 | 4 = 2*2 | 9 = 3*3 etc. | 16 | 25 | 100 | 10000 |
a.) 13 | b.) 23 | c.) 33 | d.) 43 | e.) 53 | f.) 103 | g.) 1003 |
1 | 8 = 2*2*2 | 27 = 3*3*3 etc. | 64 | 125 | 1000 | 1000000 |
a.) 21 | b.) 22 | c.) 23 | d.) 24 | e.) 101 | f.) 102 | g.) 103 |
2 | 4 = 2*2 | 8 = 2*2*2 etc. | 16 | 10 | 100 | 1000 |
a.) log22 | b.) log24 | c.) log28 | d.) log216 | e.) log1010 | f.) log10100 | g.) log101000 |
1 | 2 | 3 | 4 | 1 | 2 | 3 |
a.) 100N2, N = 10 | b.) 0.01N3, N = 10 | c.) 100N2, N = 100 | d.) 0.01N3, N = 100 |
10000 = 100 * (10*10) etc. | 10 | 1000000 | 10000 |
a.) 100N2 | b.) 0.01N3 | c.) Which has the larger order, a. or b. ? |
O(N2) | O(N3) | b. has the larger order because N3 is a higher power than N2. |
for (i = 0; i < n; i++) sum = sum + a[i]O(N), also called linear or first-order. This code is O(N) because it just has a single loop, so the execution time is proportional to
n
.
for (i = 0; i < n; i++) for (j = i; j < n; j++) sum = sum + a[i]*b[j]O(N2), also called squared or quadratic. This code is O(N2) because it has two nested loops, so the execution time is proportional to
n
squared --
the body of the inner
loop is executed (up to) n
times
each time the body of the outer loop is executed.