lecture11

lecture11 - Wednesday,Feb17 th...

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

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

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

View Full DocumentRight 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
Background 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.”
Background image of page 3

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

View Full DocumentRight 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.”
Background 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)
Background image of page 5

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

View Full DocumentRight 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∙N 2 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?
Background image of page 6
How Fast is That Algorithm? “I’m trying to sort  N numbers .” Algorithm A  takes  5∙N 2   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 
Background image of page 7

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

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

Page1 / 53

lecture11 - Wednesday,Feb17 th...

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

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