# lastweek - Performance Categories of Algorithms Sublinear...

This preview shows pages 1–8. Sign up to view the full content.

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

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

View Full Document
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

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

View Full Document
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

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

View Full Document
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 ?

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern