lecture_E7_07_Complexity_2p

lecture_E7_07_Complexity_2p - 1 • Evaluating Algorithms...

Info iconThis preview shows pages 1–6. 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: 1 • Evaluating Algorithms • Time as a function of Size • Big-O Notation Lecture 6: Computational Complexity • Big-O and Plotting the Time • Time Complexity of Sorting Algorithms Evaluating Algorithms What makes an algorithm or function "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? 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 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 You can also use the command cputime, which if you diff (i.e. cputime [at the end of the program] minus cputtime [at the start of the program]) will return the amount of computing time for this process (excluding other processes in the computer) Example of linar and quadratic number of operations Single loop Linear number of operations: at each iteration, perform this instruction 4 Example of linear and quadratic number of operations Single loop Linear number of operations: at each iteration, perform this instruction Double loop (quadratic) Same operation inside each loop Example of linear and quadratic number of operations Loops n from 1 to nMax Executes the first function with an array of size 2^n Executes the second function with an array of size 2^n Plots the resulting computing times 5 Example of linear and quadratic number of operations...
View Full Document

This note was uploaded on 09/07/2011 for the course ENGIN 7 taught by Professor Horowitz during the Spring '08 term at Berkeley.

Page1 / 19

lecture_E7_07_Complexity_2p - 1 • Evaluating Algorithms...

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

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