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: 06 Algorithm costs: time, space, and energy Best case, worst case, average case analysis Counting instructions and asymptotic analysis BigO, bigOmega, bigTheta notation Introduction to algorithm measurement CSE 12 Analysis and Measurement of Algorithms Writing good software Keep in mind the characteristics of good software: robustness : a programs ability to spot exceptional conditions and deal with them or shutdown gracefully correctness : does the program do what it is supposed to do? efficiency : all programs use resources (time and space and energy, i.e. CPU cycles and memory and battery or wall power); how can we measure efficiency so that we can compare algorithms? Efficiency and Cost Functions An algorithms efficiency can be described by: time complexity or cost how long it takes to execute. In general, less time is better! space complexity or cost how much computer memory it uses. In general, less space is better! energy complexity or cost how much energy uses. In general, less energy is better! Costs are usually given as functions of the size of the input to the algorithm: A big instance of the problem will probably take more resources to solve than a small one, but how much more? Cost function measurement vs. analysis For a given algorithm, if the size of the input is n , we would like to know: T( n ) , the time cost of solving the problem S( n ) , the space cost of solving the problem E( n ) , the energy cost of solving the problem Two approaches: We could implement the algorithm and run it and measure the time, memory, and energy usage Or we can analyze the written algorithm Algorithm cost analysis A way to start to do algorithm time cost analysis: Write down the algorithm that solves the problem Decide what size of the problem means for this kind of problem Count up the number of instructions the algorithm would execute, as a function of n , the size of the problem it is solving But note that different languages for writing the same algorithm might require a different number of instructions Java will probably require fewer than C which will require fewer than assembly language, etc. So, a precise count of the number of instructions is, arguably, too much detail we will need to consider how to abstract away from nonessential detail Algorithm cost cases Its important to distinguish among different kinds of cases that can occur when running a given algorithm to solve a problem of size n Best case : for all inputs of size n , which has the lowest cost? optimistic, but useful for a lower bound on cost Worst case : for all inputs of size n , which has the highest cost?...
View
Full
Document
This note was uploaded on 03/27/2012 for the course CSE 12 taught by Professor Gary during the Fall '08 term at UCSD.
 Fall '08
 Gary
 Algorithms

Click to edit the document details