This preview shows pages 1–7. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 4/13/2008 1 Evaluating Algorithms Time as a function of Size BigO Notation Lecture 20: Computational Complexity BigO 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. BigO 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 BigO Notation BigO Notation BigO 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 BigO 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.
 Spring '08
 Patzek

Click to edit the document details