Lecture_complexity_2p - 4/13/2008 1 Evaluating Algorithms...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: 4/13/2008 1 Evaluating Algorithms Time as a function of Size Big-O Notation Lecture 20: Computational Complexity Big-O and Plotting the Time Time Complexity of Sorting Algorithms Evaluating Algorithms What makes an algorithm "good" or "bad"? Obviously, an algorithm has to produce correct output to be "good". But what else? Another way of asking this question: If we have two algorithms, and they both do the same job, which one should we use? Example: Bubble Sort and Quick Sort both produce the same result. How should you decide which one to use? 4/13/2008 2 Evaluating Algorithms Two major criteria: 1) How much time the algorithm takes 2) How much space (memory) it takes We will consider time first. Time as a function of Data Size There's usually some sort of "size" of the problem that affects how long an algorithm takes. Example: Sorting a list of 100,000 numbers should take longer than sorting a list of 10 numbers. Task Problem size Sort a list of numbers Length of the list Find the shortest path from Size of the map (number of Find the shortest path from A to B in a street map Size of the map (number of roads, intersections, etc) Count the number of times a certain sentence appears in a book Length of the book and length of the target sentence 4/13/2008 3 Time as a function of Data Size In MATLAB, we can measure time using the tic and toc functions. tic : start the timer toc: stop the timer, report how long since tic Time as a function of Data Size What does this tell us? ... the time/size relationship seems to be a bit like a parabola... ... on a IBM ThinkPad T60p, bubble sorting 5000 numbers takes about 1 second... Does it tell us anything about how fast bubble sorting is on your computer? 4/13/2008 4 Time as a function of Data Size Things that affect how fast an algorithm runs: z Processor speed z Processor architecture z Memory size z Memory speed z Memory architecture z Operating system There are so many different factors affecting run time, that in most cases, we don't try to characterize exactly how fast an algorithm runs. Big-O Notation We talk about the asymptotic behavior of the algorithm... how the running time behaves as the size goes to infinity. Why is this little bump here? We don't really care. The behavior at small sizes doesn't matter. (0.05 seconds vs 0.04 seconds... not a big deal!) 4/13/2008 5 Big-O Notation Big-O Notation Big-O notation is used to describe sets of functions according to how they grow. Examples because as because there isn't any big enough for as 4/13/2008 6 Big-O Notation If you have a function and you want to find its "big- O" class: just throw away everything except the "biggest" term (i.e. the one that grows the most as ) x & and throw away the constant in front too....
View Full Document

This note was uploaded on 03/04/2009 for the course E 7 taught by Professor Patzek during the Spring '08 term at University of California, Berkeley.

Page1 / 35

Lecture_complexity_2p - 4/13/2008 1 Evaluating Algorithms...

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

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