02. Analysis of Algorithms II

02. Analysis of Algorithms II - Maggie Johnson CS103B...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Maggie Johnson Handout #3 CS103B Analysis of Algorithms: The Non-recursive Case Thanks to Mehran Sahami for portions of this handout. Key topics: * Introduction * Generalizing Running Time * Doing a Timing Analysis * Big-Oh Notation * Big-Oh Operations * Analyzing Some Simple Programs - no subprogram calls * Worst-Case and Average Case Analysis * Analyzing Programs with Non-Recursive Subprogram Calls * Classes of Problems Why Analyze Algorithms? There may be several different ways to solve a particular problem. For example, there are several methods for sorting numbers. How can you decide which method is the best in a certain situation? How would you define "best" – is it the fastest method or the one that takes up the least amount of memory space? Understanding the relative efficiencies of algorithms designed to do the same task is very important in every area of computing. This is how computer scientists decide which algorithm to use for a particular application. In the 1950's and 60's, many mathematicians and computer scientists developed the field of algorithm analysis. One researcher in particular, Donald Knuth, wrote a three-volume text called The Art of Computer Programming that provided a foundation for the subject. Interestingly enough, Prof. Knuth also used to teach at Stanford until his retirement several years ago. He is now in the process of writing more volumes of his seminal book series, and still occasionally gives talks on campus. As mentioned earlier, an algorithm can be analyzed in terms of time efficiency or space utilization. We will consider only the former right now. The running time of an algorithm is influenced by several factors: 1) Speed of the machine running the program 2) Language in which the program was written. For example, programs written in assembly language generally run faster than those written in C or C++, which in turn tend to run faster than those written in Java. 3) Efficiency of the compiler that created the program 4) The size of the input: processing 1000 records will take more time than processing 10 records.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
– 2 – 5) Organization of the input: if the item we are searching for is at the top of the list, it will take less time to find it than if it is at the bottom. The first three items in the list are problematic. We don’t want to use an exact measurement of running time: To say that a particular algorithm written in Java and running on a Pentium IV takes some number of milliseconds to run tells us nothing about the general time efficiency of the algorithm, because the measurement is specific to a given environment. The measurement will be of no use to someone in a different environment. We need a general metric for the time efficiency of an algorithm; one that is independent of processor or language speeds, or compiler efficiency. The fourth item in the list is not environment-specific, but it is an important
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 21

02. Analysis of Algorithms II - Maggie Johnson CS103B...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online