23.11.2014 Views

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

4.2.4 Asymptotic Analysis<br />

Suppose two algorithms solv<strong>in</strong>g the same problem are available: an algorithm A,<br />

which has a runn<strong>in</strong>g time of O(n), <strong>and</strong> an algorithm B, which has a runn<strong>in</strong>g time of<br />

O(n 2 ). Which algorithm is better? We know that n is O(n 2 ), which implies that<br />

algorithm A is asymptotically better than algorithm B, although for a small value of<br />

n, B may have a lower runn<strong>in</strong>g time than A.<br />

We can use the big-Oh notation to order classes of functions by asymptotic growth<br />

rate. Our seven functions are ordered by <strong>in</strong>creas<strong>in</strong>g growth rate <strong>in</strong> the sequence<br />

below, that is, if a function f(n) precedes a function g(n) <strong>in</strong> the sequence, then f(n) is<br />

O(g(n)):<br />

1 log n n nlog n n 2 n 3 2 n .<br />

We illustrate the growth rates of some important functions <strong>in</strong> Figure 4.2.<br />

Table 4.2: Selected values of fundamental functions <strong>in</strong><br />

algorithm analysis.<br />

n<br />

logn<br />

n<br />

nlogn<br />

n 2<br />

n 3<br />

2 n<br />

8<br />

3<br />

8<br />

24<br />

64<br />

512<br />

234

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!