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.

Focus<strong>in</strong>g on the Worst Case<br />

An average-case analysis usually requires that we calculate expected runn<strong>in</strong>g<br />

times based on a given <strong>in</strong>put distribution, which usually <strong>in</strong>volves sophisticated<br />

probability theory. Therefore, for the rema<strong>in</strong>der of this book, unless we specify<br />

otherwise, we will characterize runn<strong>in</strong>g times <strong>in</strong> terms of the worst case, as a<br />

function of the <strong>in</strong>put size, n, of the algorithm.<br />

Worst-case analysis is much easier than average-case analysis, as it requires only<br />

the ability to identify the worst-case <strong>in</strong>put, which is often simple. Also, this<br />

approach typically leads to better algorithms. Mak<strong>in</strong>g the st<strong>and</strong>ard of success for<br />

an algorithm to perform well <strong>in</strong> the worst case necessarily requires that it will do<br />

well on every <strong>in</strong>put. That is, design<strong>in</strong>g for the worst case leads to stronger<br />

algorithmic "muscles," much like a track star who always practices by runn<strong>in</strong>g up<br />

an <strong>in</strong>cl<strong>in</strong>e.<br />

4.2.3 Asymptotic Notation<br />

In general, each basic step <strong>in</strong> a pseudo-code description or a high-level language<br />

implementation corresponds to a small number of primitive operations (except for<br />

method calls, of course). Thus, we can perform a simple analysis of an algorithm<br />

written <strong>in</strong> pseudo-code that estimates the number of primitive operations executed<br />

up to a constant factor, by pseudo-code steps (but we must be careful, s<strong>in</strong>ce a s<strong>in</strong>gle<br />

l<strong>in</strong>e of pseudo-code may denote a number of steps <strong>in</strong> some cases).<br />

228

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

Saved successfully!

Ooh no, something went wrong!