lec04

# lec04 - CSE 12 Analysis and Measurement of Algorithms...

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

04-1/26 Algorithm costs: time, space, and energy Best case, worst case, average case analysis Counting instructions and asymptotic analysis Big-O, big-Omega, big-Theta notation Introduction to algorithm measurement CSE 12 Analysis and Measurement of Algorithms

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

View Full Document
Writing good software Keep in mind the characteristics of good software: robustness : a program’s 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?
Cost functions An algorithm’s performance 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?

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

View Full Document
Determining algorithm costs 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 To perform 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 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

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

View Full Document
Algorithm cost cases Sometimes it’s useful to distinguish among different 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 one has the lowest cost? optimistic, but
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 27

lec04 - CSE 12 Analysis and Measurement of Algorithms...

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

View Full Document
Ask a homework question - tutors are online