### Introduction to Performance Analysis of computer algorithms

• Performance measures in algorithm analysis

• There are two important measures that we want to know about a computer algorithm:

• The running time

Different kinds of running times:

 The best-case running time (rarely used) The average running time (often used, but hard to compute) The worst-case running time (often used, and easier to compute)

• The amount of memory needed

 We must count the number of variables used by the program.

E.g.: int A[1000]; is counted as 1000 variables !

• Notable fact:

• It is sometimes possible to trade off running time against memory usage

• There may be 2 different algorithms to solve the same problem where:

 Algorithm 1 runs very slowly but uses very little memory Algorithm 2 runs very fast but uses a hugh amount of memory

That's why it is important to calculate both the running time and the memory usage of an algorithm.

• NOTE:

 Counting the number of variables used in a program is rather straightforward We will focus mainly on running time analysis.

• What to count in a running time analysis

• Bad units to measure running time :

 Number of seconds of computer time

This measure is bad because the same algorithm will run slower on a older computer (e.g., on an ancient PC that has a 80386 processer)

• Good units to measure running time :

 Count the number of program statements Count the number of a "fundamental" operations

• "Fundamental" operations

• Fact:

• A computer algorithm often perform the same sequence of statements

Example:

 When you sort items, the algorithm will repeatedly exchange (swap) data items to put them in sequence

• The fundamental operation of an algorithm is the operation that is repeated over and over again.

 The fundamental operation is a commonly used unit for measuring the run time complexity

• Different algorithms will use different fundamental operation