last - Performance Categories of Algorithms An Exponential...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
1 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 ) 2 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); } }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
3 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: 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
Background image of page 2
5 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. 6 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 )
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
7 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 ? 2.
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 06/12/2011.

Page1 / 9

last - Performance Categories of Algorithms An Exponential...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online