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.

primarily as slopes. Even so, the exponential function<br />

grows too fast to display all its values on the chart. Also,<br />

we use the scientific notation for numbers, where, aE+b<br />

denotes a10 b .<br />

The Ceil<strong>in</strong>g <strong>and</strong> Floor Functions<br />

One additional comment concern<strong>in</strong>g the functions above is <strong>in</strong> order. The value of<br />

a logarithm is typically not an <strong>in</strong>teger, yet the runn<strong>in</strong>g time of an algorithm is<br />

usually expressed by means of an <strong>in</strong>teger quantity, such as the number of<br />

operations performed. Thus, the analysis of an algorithm may sometimes <strong>in</strong>volve<br />

the use of thefloor function <strong>and</strong> ceil<strong>in</strong>g function, which are def<strong>in</strong>ed respectively<br />

as follows:<br />

• x = the largest <strong>in</strong>teger less than or equal to x.<br />

• x = the smallest <strong>in</strong>teger greater than or equal to x.<br />

4.2 Analysis of <strong>Algorithms</strong><br />

In a classic story, the famous mathematician Archimedes was asked to determ<strong>in</strong>e if a<br />

golden crown commissioned by the k<strong>in</strong>g was <strong>in</strong>deed pure gold, <strong>and</strong> not part silver, as<br />

an <strong>in</strong>formant had claimed. Archimedes discovered a way to perform this analysis<br />

while stepp<strong>in</strong>g <strong>in</strong>to a (Greek) bath. He noted that water spilled out of the bath <strong>in</strong><br />

proportion to the amount of him that went <strong>in</strong>. Realiz<strong>in</strong>g the implications of this fact,<br />

he immediately got out of the bath <strong>and</strong> ran naked through the city shout<strong>in</strong>g, "Eureka,<br />

eureka!," for he had discovered an analysis tool (displacement), which, when<br />

comb<strong>in</strong>ed with a simple scale, could determ<strong>in</strong>e if the k<strong>in</strong>g's new crown was good or<br />

not. That is, Archimedes could dip the crown <strong>and</strong> an equal-weight amount of gold<br />

223

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

Saved successfully!

Ooh no, something went wrong!