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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Each entry is a function of m, the previous maximum<br />

problem size.<br />

Runn<strong>in</strong>g Time<br />

New Maximum Problem Size<br />

400n<br />

256m<br />

2n 2<br />

16m<br />

2 n<br />

m + 8<br />

4.2.5 Us<strong>in</strong>g the Big-Oh Notation<br />

Hav<strong>in</strong>g made the case of us<strong>in</strong>g the big-Oh notation for analyz<strong>in</strong>g algorithms, let us<br />

briefly discuss a few issues concern<strong>in</strong>g its use. It is considered poor taste, <strong>in</strong><br />

general, to say "f(n) ≤ O(g(n))," s<strong>in</strong>ce the big-Oh already denotes the "less-than-orequal-to"<br />

concept. Likewise, although common, it is not fully correct to say "f(n) =<br />

O(g(n))" (with the usual underst<strong>and</strong><strong>in</strong>g of the "=" relation), s<strong>in</strong>ce there is no way to<br />

make sense of the statement "O(g(n)) = f(n)." In addition, it is completely wrong to<br />

say "f(n) ≥ O(g(n))" or "f(n) > O(g(n))," s<strong>in</strong>ce the g(n) <strong>in</strong> the big-Oh expresses an<br />

upper bound on f(n). It is best to say,<br />

"f(n) is O(g(n))."<br />

For the more mathematically <strong>in</strong>cl<strong>in</strong>ed, it is also correct to say,<br />

"f(n) O(g(n)),"<br />

for the big-Oh notation is, technically speak<strong>in</strong>g, denot<strong>in</strong>g a whole collection of<br />

functions. In this book, we will stick to present<strong>in</strong>g big-Oh statements as "f(n) is<br />

O(g(n))." Even with this <strong>in</strong>terpretation, there is considerable freedom <strong>in</strong> how we can<br />

use arithmetic operations with the big-Oh notation, <strong>and</strong> with this freedom comes a<br />

certa<strong>in</strong> amount of responsibility.<br />

Some Words of Caution<br />

A few words of caution about asymptotic notation are <strong>in</strong> order at this po<strong>in</strong>t. First,<br />

note that the use of the big-Oh <strong>and</strong> related notations can be somewhat mislead<strong>in</strong>g<br />

238

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

Saved successfully!

Ooh no, something went wrong!