This
** preview**
has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*This
** preview**
has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*This
** preview**
has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*This
** preview**
has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*
**Unformatted text preview: **Performance Categories of Algorithms • Sublinear - O(logN) • Linear - O(N) • Nearly linear - O(NlogN) • Quadratic - O(N 2 ) • Exponential - O(2 N ) O(N!) O(N N ) 1 An Exponential Algorithm Towers of Hanoi Problem : involves moving a specified number of disks (N) that are all different sizes from one tower to another. void tower(int n, char start, char finish, char temp) { if (n == 1) printf(“Move from %c to %c\n”, start, finish); else { tower(n-1, start, temp, finish); printf(“Move from %c to %c \n”, start, finish); tower(n-1, temp, finish, start); } } 2 Towers of Hanoi – Runtime • For 3 rings - 7 operations o Cost = (2 N ) – 1 • Each time we increment N by 1, we double the amount of work • Run-time trace of function tower with 4 disks: 3 Original call with n = 4 Call with n = 3 Call with n = 3 Call with n = 2 Call with n = 2 Call with n = 2 Call with n = 2 Call with n = 1 Call with n = 1 Call with n = 1 Call with n = 1 Call with n = 1 Call with n = 1 Call with n = 1 Call with n = 1 4 Effects of Exponents Consider Towers of Hanoi (or other 2 N algorithm) for N of only 256: Time cost is a number with 78 digits to the left of the decimal. For comparison: • Number of microseconds since the Big Bang: a number with 24 digits. • Number of protons (est’d) in the known universe: a number with 77 digits. 5 Reasonable vs Unreasonable Reasonable Algorithms ... • Have N only as a polynomial factor- O (logN)- O (N)- O (N K ) where K is a constant Unreasonable Algorithms ... • Have N as an exponential factor- O (2 N )- O (N!)- O (N N ) 6 Example Problems 1. Algorithm A runs in O(N 2 ) time, and for an input size of 4, the algorithm runs in 10 milliseconds, how long can you expect it to take to run on an input size of 16...

View
Full
Document