11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

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.

44 Chap. 2 M<strong>at</strong>hem<strong>at</strong>ical PreliminariesWe can use a similar process to prove many recursive programs correct. Thegeneral form is to show th<strong>at</strong> the base cases perform correctly, <strong>and</strong> then to use theinduction hypothesis to show th<strong>at</strong> the recursive step also produces the correct result.Prior to this, we must prove th<strong>at</strong> the function always termin<strong>at</strong>es, which might alsobe done using an induction proof.2.7 Estim<strong>at</strong>ionOne of the most useful life skills th<strong>at</strong> you can gain from your computer sciencetraining is the ability to perform quick estim<strong>at</strong>es. This is sometimes known as “backof the napkin” or “back of the envelope” calcul<strong>at</strong>ion. Both nicknames suggestth<strong>at</strong> only a rough estim<strong>at</strong>e is produced. Estim<strong>at</strong>ion techniques are a st<strong>and</strong>ard partof engineering curricula but are often neglected in computer science. Estim<strong>at</strong>ionis no substitute for rigorous, detailed analysis of a problem, but it can serve toindic<strong>at</strong>e when a rigorous analysis is warranted: If the initial estim<strong>at</strong>e indic<strong>at</strong>es th<strong>at</strong>the solution is unworkable, then further analysis is probably unnecessary.Estim<strong>at</strong>ion can be formalized by the following three-step process:1. Determine the major parameters th<strong>at</strong> affect the problem.2. Derive an equ<strong>at</strong>ion th<strong>at</strong> rel<strong>at</strong>es the parameters to the problem.3. Select values for the parameters, <strong>and</strong> apply the equ<strong>at</strong>ion to yield an estim<strong>at</strong>edsolution.When doing estim<strong>at</strong>ions, a good way to reassure yourself th<strong>at</strong> the estim<strong>at</strong>e isreasonable is to do it in two different ways. In general, if you want to know wh<strong>at</strong>comes out of a system, you can either try to estim<strong>at</strong>e th<strong>at</strong> directly, or you canestim<strong>at</strong>e wh<strong>at</strong> goes into the system (assuming th<strong>at</strong> wh<strong>at</strong> goes in must l<strong>at</strong>er comeout). If both approaches (independently) give similar answers, then this shouldbuild confidence in the estim<strong>at</strong>e.When calcul<strong>at</strong>ing, be sure th<strong>at</strong> your units m<strong>at</strong>ch. For example, do not add feet<strong>and</strong> pounds. Verify th<strong>at</strong> the result is in the correct units. Always keep in mind th<strong>at</strong>the output of a calcul<strong>at</strong>ion is only as good as its input. The more uncertain yourvalu<strong>at</strong>ion for the input parameters in Step 3, the more uncertain the output value.However, back of the envelope calcul<strong>at</strong>ions are often meant only to get an answerwithin an order of magnitude, or perhaps within a factor of two. Before doing anestim<strong>at</strong>e, you should decide on acceptable error bounds, such as within 25%, withina factor of two, <strong>and</strong> so forth. Once you are confident th<strong>at</strong> an estim<strong>at</strong>e falls withinyour error bounds, leave it alone! Do not try to get a more precise estim<strong>at</strong>e thannecessary for your purpose.Example 2.18 How many library bookcases does it take to store bookscontaining one million pages? I estim<strong>at</strong>e th<strong>at</strong> a 500-page book requires

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

Saved successfully!

Ooh no, something went wrong!