Maggie Johnson
Handout #3
CS103B
Analysis of Algorithms: The Nonrecursive Case
Thanks to Mehran Sahami for portions of this handout.
Key topics:
* Introduction
* Generalizing Running Time
* Doing a Timing Analysis
* BigOh Notation
* BigOh Operations
* Analyzing Some Simple Programs  no subprogram calls
* WorstCase and Average Case Analysis
* Analyzing Programs with NonRecursive 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 threevolume 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.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document– 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 environmentspecific, but it is an important
This is the end of the preview.
Sign up
to
access the rest of the document.
 Winter '08
 SAHAMI,M
 Algorithms, Analysis of algorithms, Computational complexity theory, running time, Donald Knuth

Click to edit the document details