Keywords• Algorithm: A well defined finite set of steps a computer follows to solve a problem
• Algorithm Analysis: The process of determining the amount of resources required during the execution of an algorithm
• Computer Program: An instance , or concrete representation, for an algorithm in some programming language
Properties of Algorithms• It must be correct• It must be composed of a series of concrete steps
• There can be no ambiguity as to which step will be performed next
• It must be composed of a finite number of steps• It must terminate
Why Analyze Algorithms?• An algorithm can be analyzed in terms of time and space. The running time of an algorithm is influenced by several factors
Speed of the machine running the program Language in which the program was written Efficiency of the compiler that created the program
The size of the input Organization of the input
Two Conflicting Goals• There are often many approaches (algorithms) to solve a problem. How do we choose between them?
• At the heart of computer program design there are two (sometimes conflicting) goals
Goal ONE: To design an algorithm that is easy to understand, code, debug Software Engineering
Goal TWO: To design an algorithm that makes efficient use of the computer’s resources Data Structures and Algorithm Analysis
Natural Size of a Problem• The problems have a natural “size” (N)• N = Amount of data to be processed• Resources used is proportional to f(N)• f is a function• Resource is most often time
Definitions• Average Case: The amount of time a program might be expected to take on “typical” input data
• Worst Case: The amount of time a program would take on the worst possible input configuration
Experimental Comparison• Consider a C program• C program Machine code• How long one C statement might take to execute?• Several problems arise in experimental comparison
Resources are being shared Some programs are extremely sensitive to their input data
Many programs of interest are not well understood
A Framework for Analysis• Characterize the data that is to be used as input and decide what type of analysis is appropriate: Determined by the properties of the algorithm
• Identify abstract operations upon which the algorithm is based: Determined by the properties of the computer
• Proceeding the mathematical analysis itself to find worst and average case values
The Upper Bound of Running Time• The running time is always less than some “upper bound” no matter what the input
• Worst case running time corresponds to that upper bound
• Average case running time corresponds to the time taken for a random input of data
Algorithm Profiling• While the number of abstract operations involved can be in principle large, it is usually the case that the performance of the algorithms we consider depends on only a few quantities
• Example: Instruction Frequency Counts• A Quote: “90% of the time is spent in 10% of the code”
The Cyclic Process of Analysis• Analysis of an algorithm is a cyclic process
Analyze
Refine
Estimate
Improvements to the implementation