cs32w09dis6

# cs32w09dis6 - CS32 Introduction to Computer Science II...

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

Discussion 3A Notes (Week 7, February 20) TA: Brian Choi ([email protected]) Section Webpage: http://www.cs.ucla.edu/~schoi/cs32 Algorithm Complexity So far we have been mainly concerned with getting things done. From now on we will talk about getting things done with efficiency . Writing programs that make use of available resources (e.g. time and memory space) wisely is not an easy task. Because memory and hard disks are cheap these days, we’re more interested in how fast a code can run than how much memory it takes. To start with, we need to know how to measure the “efficiency.” This is done through what is called Big-O analysis or asymptotic analysis . The question big-O analysis attempts to answer is as follows: Given an input of size n, approximately how long does the algorithm take to finish the task? It is clear that most known algorithms take longer if the input size n is large. Think of sorting 10 items in an array, and sorting 1000 items in an array. Apparently, it will take must longer to sort 1000 items, but how longer? Big-O analysis gives you a rough idea the dependency of running time on the input size. Big-O Notation Let’s start with a formal definition. Let f(x) and g(x) be two functions of real numbers. Then we say: if and only if We read O(g(x)) “big-O of g(x)”. For example, if O(x 2 ) is read “big-O of x squared”. Big-O is supposed to give you an upper-bound to the function. Here are some examples: Because the way big-O is defined, a function can take on big-O notations. f(x) = x 2 + 5x is O(x 2 ), O(x 3 ), O(x 4 ), and so on, at the same time. However, we are mostly interested in the tightest bound we can find. In any case, you don’t have to remember this formal definition. But just remember that: Big-O gives you the upper-bound on the function’s growth. We use big-O to measure the algorithm’s performance. It is the running time of an algorithm with respect

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 11/07/2009 for the course CS 32 taught by Professor Davidsmallberg during the Winter '08 term at UCLA.

### Page1 / 4

cs32w09dis6 - CS32 Introduction to Computer Science II...

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

View Full Document
Ask a homework question - tutors are online