12.07.2015 Views

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

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

Sec. 3.11 Empirical <strong>Analysis</strong> 893.11 Empirical <strong>Analysis</strong>This chapter has focused on asymp<strong>to</strong>tic analysis. This is an analytic <strong>to</strong>ol, wherebywe model the key aspects of an algorithm <strong>to</strong> determine the growth rate of the algorithmas the input size grows. As pointed out previously, there are many limitations<strong>to</strong> this approach. These include the effects at small problem size, determiningthe finer distinctions between algorithms with the same growth rate, <strong>and</strong> the inherentdifficulty of doing mathematical modeling for more complex problems.An alternative <strong>to</strong> analytical approaches are empirical approaches. The most obviousempirical approach is simply <strong>to</strong> run two competi<strong>to</strong>rs <strong>and</strong> see which performsbetter. In this way we might overcome the deficiencies of analytical approaches.Be warned that comparative timing of programs is a difficult business, oftensubject <strong>to</strong> experimental errors arising from uncontrolled fac<strong>to</strong>rs (system load, thelanguage or compiler used, etc.). The most important point is not <strong>to</strong> be biased infavor of one of the programs. If you are biased, this is certain <strong>to</strong> be reflected inthe timings. One look at competing software or hardware vendors’ advertisementsshould convince you of this. The most common pitfall when writing two programs<strong>to</strong> compare their performance is that one receives more code-tuning effort than theother. As mentioned in Section 3.10, code tuning can often reduce running time bya fac<strong>to</strong>r of ten. If the running times for two programs differ by a constant fac<strong>to</strong>rregardless of input size (i.e., their growth rates are the same), then differences incode tuning might account for any difference in running time. Be suspicious ofempirical comparisons in this situation.Another approach <strong>to</strong> analysis is simulation. The idea of simulation is <strong>to</strong> modelthe problem with a computer program <strong>and</strong> then run it <strong>to</strong> get a result. In the contex<strong>to</strong>f algorithm analysis, simulation is distinct from empirical comparison of twocompeti<strong>to</strong>rs because the purpose of the simulation is <strong>to</strong> perform analysis that migh<strong>to</strong>therwise be <strong>to</strong>o difficult. A good example of this appears in Figure 9.8. This figureshows the cost for inserting or deleting a record from a hash table under twodifferent assumptions for the policy used <strong>to</strong> find a free slot in the table. The y axesis the cost in number of hash table slots evaluated, <strong>and</strong> the x axes is the percentageof slots in the table that are full. The mathematical equations for these curves canbe determined, but this is not so easy. A reasonable alternative is <strong>to</strong> write simplevariations on hashing. By timing the cost of the program for various loading conditions,it is not difficult <strong>to</strong> construct a plot similar <strong>to</strong> Figure 9.8. The purpose of thisanalysis is not <strong>to</strong> determine which approach <strong>to</strong> hashing is most efficient, so we arenot doing empirical comparison of hashing alternatives. Instead, the purpose is <strong>to</strong>analyze the proper loading fac<strong>to</strong>r that would be used in an efficient hashing system<strong>to</strong> balance time cost versus hash table size (space cost).

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

Saved successfully!

Ooh no, something went wrong!