{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture 10 - Algorithmic complexity, Basic Sorting Algorithms

Lecture 10 - Algorithmic complexity, Basic Sorting Algorithms

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

View Full Document Right Arrow Icon
Wednesday, Feb 15th Big Oh  aka  “How Fast Is that Algorithm?” Sorting Algorithms, part I
Image of page 1

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

View Full Document Right Arrow Icon
How Fast is That Algorithm? Sometimes we want to ask  “How fast is that algorithm?” Or: “Which algorithm is  faster,  A  or  B ?” Question:  How can you measure the “speed” of an  algorithm? A B
Image of page 2
Right! We could measure the time it takes for an  algorithm to run. But that has flaws!  What are  they? How Fast is That Algorithm? Carey:  “My algorithm finished in 31 seconds.” Cedric:  “Mine finished in 30 seconds, it’s better!” Carey:  “Not so fast! How fast is your PC? Mine is 1GHZ.” Cedric:  “Err… Mine is 3GHZ.” Carey:  “Aha – so my algorithm is really almost 3x faster!” Cedric:  “Sigh. Carey’s right again.”
Image of page 3

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

View Full Document Right Arrow Icon
Ok, so simply measuring the run-time of an algorithm isn’t really  all that useful. What if instead we measure an algorithm based on:  how many computer instructions it takes  to solve a problem of a given size How Fast is That Algorithm? Carey:  “My algorithm took 370 million instructions to sort 1,000  numbers.” Cedric:  “Dude – you SUCK! Mine only took only 5 million instructions, it’s  better!” Carey:  “Not so fast grasshopper! Mine might be slower on 1,000 numbers, but  what if we sort 1 million numbers?” Cedric:  “Hmm. I don’t know – I haven’t tried.”
Image of page 4
So just  rating an algorithm  based on how many steps it takes on a  particular  set of data  doesn’t tell us much. We’d like to understand how our algorithm performs  under all circumstances ! How Fast is That Algorithm? An algorithm might look efficient when applied to a small amount of data  (e.g., 1,000 numbers) But really “blow chunks” when applied to a lot of data  (e.g. 1 billion numbers)
Image of page 5

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

View Full Document Right Arrow Icon
“I’m trying to sort  1000 numbers .” Algorithm A  takes  5 million  instructions to do that.” Algorithm B  takes  307 million  instructions to do that.” N 5∙N2 37,000·N Hmmm. What else could we do? Right!  What if we specify  the number of instructions used by an algorithm  as a function of the size of the input data. Now we can predict which algorithm will be faster  for any value of N! How Fast is That Algorithm?
Image of page 6
How Fast is That Algorithm? “I’m trying to sort  N numbers .” Algorithm A  takes  5∙N2  instructions to do that.” Algorithm B  takes  37,000∙N  instructions to do that.” Ok, what if we’re sorting  1,000  numbers: Algorithm A  takes  5M  instructions.” Algorithm B  takes  37M  instructions.” Ok, what if we’re sorting  10,000  numbers: Algorithm A  takes  500M  instructions.” Algorithm B  takes  370M  instructions.” Ok, what if we’re sorting 
Image of page 7

Info icon This 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