Presentation is loading. Please wait.

Presentation is loading. Please wait.

ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 11 – September 25, 2001.

Similar presentations


Presentation on theme: "ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 11 – September 25, 2001."— Presentation transcript:

1 ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 11 – September 25, 2001

2 ICOM 4035Dr. Manuel Rodriguez Martinez2 Readings Chapter 6 of textbook: Algorithm Analysis Handout: “Tiempo de Ejecucion”

3 ICOM 4035Dr. Manuel Rodriguez Martinez3 Algorithms and their Analysis An algorithm is simply a set of instructions used to solve a given problem. Each algorithm receives an input, and produces an output. Example 1 : find operation in a bag. –Input: the bag and the object to be searched. –Output: true if the object is in the bag, or false otherwise. Example 2: intersection between two sets –Input: the two sets –Output: the set that is result of their intersection. Algorithm analysis is the process of evaluating the performance of an algorithm.

4 ICOM 4035Dr. Manuel Rodriguez Martinez4 Algorithm Analysis An algorithm can be characterize based on its performance behavior. Performance could be measured in terms of: –Expected time of execution –Expected amount of resources to be used Memory Disk Network bandwidth Execution time is the most commonly use. The execution time typically depend on the amount of input the algorithm receives. –A 300MB file takes more time to be read than a 20MB file.

5 ICOM 4035Dr. Manuel Rodriguez Martinez5 Cost Formulas We can design a formula to estimate the execution time of an algorithm. Example: Reading N megabytes from a disk that has a throughput of 10MB/sec. –Execution time: T(N) = N/10 –For: N = 10MB, T(10) = 1 sec N = 110MB, T(110) = 11 sec N = 1000MB, T(1000) = 100 sec

6 ICOM 4035Dr. Manuel Rodriguez Martinez6 The problem with cost formulas It is often difficult, unnecessary or irrelevant to have an exact cost estimate –Time likely to be dependant on: Hardware –1GHZ PENTIUM vs. 500MHZ POWER PC –1GB of RAM vs 200MB of I-RAM –20 GB Ultra SCSI disk vs 20 GB Ultra ATA Software –GNU G++ compiler –MS Visual Basic Development technique –Pointers vs Arrays –call by value vs. call by reference

7 ICOM 4035Dr. Manuel Rodriguez Martinez7 Simpler cost formulas It is more convenient to express the execution time in terms on the amount of input. –Often termed the size of the input. Instead of an exact formula, get an estimate of the cost operation as an expression based on number of input items being manipulated. For example, reading an n MB file can be simply express as : T(n) = c * n, where c would be a constant that captures all system dependent cost values (i.e. disk speed).

8 ICOM 4035Dr. Manuel Rodriguez Martinez8 Some sample costs T(n) = 3n^2 + 2n T(n) = 5n + 1 T(n) = 3 T(n) = 2^n + n^3 + 1

9 ICOM 4035Dr. Manuel Rodriguez Martinez9 Bounds for cost formulas It is more convenient to express the execution time in terms on the amount of input. –Often termed the size of the input. Instead of an exact formula, get a bound y that indicates that the execution time will be bounded by y This bound y will be a function g(n) that indicates that the execution time T(n) will always be smaller than g(n) multiplied by a constant factor c. –In other words, T(n)  c*g(n), for all n0  n, and c > 0 This bound refers to a worst case scenario. –In the worst case, T(n)  c*g(n), for all n0  n, and c > 0

10 ICOM 4035Dr. Manuel Rodriguez Martinez10 Big-Oh notation Gives a bound for the execution time in a worst case scenario. Mathematically this: – T(n)  c*g(n), for all n0  n, and c > 0 This is expressed as T(n) is O(g(n)), which means that T(n) is at most c times g(n). –T(n) is proportional to g(n).

11 ICOM 4035Dr. Manuel Rodriguez Martinez11 Example: Find operation in a bag Algorithm: Find x in bag b. Pseudo-code: for each element b[i] in b { if (x == b[i]){ return true; } return false; Input: bag b with n elements. The algorithm has to inspect all elements until it either finds x, or does not find it. Worst case: x is the last element or it is not in there. Algorithm has to inspect n elements in the bag. T(n) is O(n), where g(n) = n.

12 ICOM 4035Dr. Manuel Rodriguez Martinez12 Some typical bounds O(1) – constant time operation, whose execution time is independent of size. –Example: int a = 1; O(n) – linear time operation, execution time is linear with respect to input size. –Example: find operation in a bag. O(n^2) – quadratic time operation, execution time is quadratic with respect to input size. –Example: traversing a two-dimensional array. O(n^3) – cubic time operation. O(logn) – logarithm time operation, execution time is logarithmic with respect to input size. O(2^n) – exponential time operation, execution time is exponential with respect to input size.


Download ppt "ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 11 – September 25, 2001."

Similar presentations


Ads by Google