文档介绍:I
Chapter 1, Algorithms Matter
Chapter 2, The Mathematics of Algorithms
Chapter 3, Patterns and Domains
1
Algorithms Matter
Algorithms matter! Knowing which algorithm to apply under which set of circum-
stances can make a big difference in the software you produce. If you don’t believe
us, just read the following story about how Gary turned failure into ess with a
little analysis and choosing the right algorithm for the job.*
Once upon a time, Gary worked at pany with a lot of brilliant software
developers. Like anizations with a lot of bright people, there were many
great ideas and people to implement them in the software products. One such
person was Graham, who had been with pany from its inception. Graham
came up with an idea on how to find out whether a program had any memory
leaks—mon problem with C and C++ programs at the time. If a program
ran long enough and had memory leaks, it would crash because it would run out
of memory. Anyone who has programmed in a language that doesn’t support
automatic memory management and garbage collection knows this problem well.
Graham decided to build a small library that wrapped the operating system’s
memory allocation and deallocation routines, malloc( ) and free( ), with his own
functions. Graham’s functions recorded each memory allocation and deallocation
in a data structure that could be queried when the program finished. The wrapper
functions recorded the information and called the real operating system functions
to perform the actual memory management. It took just a few hours for Graham
to implement the solution and, voilà, it worked! There was just one problem: the
program ran so slowly when it was instrumented with Graham’s libraries that no
one was willing to use it. We’re talking really slow here. You could start up a
program, go have a cup of coffee—or maybe a pot of e back, and the
program would still be crawling along. This was clearly eptable.
* The names of participants anizati