lastweek - Performance Categories of Algorithms Sublinear...

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

View Full Document Right Arrow Icon
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
Image of page 1

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

View Full Document Right Arrow Icon
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
Image of page 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
Image of page 3

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

View Full Document Right Arrow Icon
4
Image of page 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
Image of page 5

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

View Full Document Right Arrow Icon
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
Image of page 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 ?
Image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern