lec16&amp;17

# lec16&amp;17 - Discrete Computation Structures CSE 2353...

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

Discrete Computation Structures CSE 2353 Bhanu Kapoor, PhD Department of Computer Science & Engineering Southern Methodist University, Dallas, TX [email protected] , 214-336-4973 October 27 and 29, 2009 Embrey 129, SMU, Dallas, Texas Lectures 16 and 17 1

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

View Full Document
Lecture 16 & 17 Agenda ± Algorithmic Complexity ± Recurrence in Algorithms 2
Big-O Notation ± We say f A ( n )=30 n+ 8is order n , or O( n ). It is, at most , roughly proportional to n . ± f B ( n )= n 2 +1 is order n 2 , or O( n 2 ). It is, at most , roughly proportional to n 2 . ± In general, an O( n 2 ) algorithm will be slower than O (n) algorithm. ± A n O( n 2 ) function will grow faster than an O (n) function. 3

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

View Full Document
More Examples … ± We say that n 4 + 100 n 2 + 10 n + 50 is of the order of n 4 or O ( n 4 ) ± We say that 10 n 3 + 2 n 2 is O ( n 3 ) ± We say that n 3 - n 2 is O ( n 3 ) e say that 10 is ) ± We say that 10 is O (1), ± We say that 1273 is O (1) 4
Big-O Visualization 5

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

View Full Document
Computing running time Algorithm 1 Algorithm 2 Cost Cost arr[0] = 0; c1 for(i=0; i<N; i++) c2 rr[1] = 0; c1 arr[i] = 0; c1 arr[1] = 0; c1 arr[i] = 0; arr[2] = 0; c1 ... arr[N-1] = 0; c1 ----------- ------------- 1+c1+ +c1 = c1 x N (N+1) x c2 + N x c1 = c1+c1+. ..+c1 c1 x N (N+1) x c2 + N x c1 (c2 + c1) x N + c2 (n) O(n) 6
Computing running time (cont.) Cost sum = 0; c1 r(i=0; i<N; i++ )c 2 for(i 0; iN ; i) c2 for(j=0; j<N; j++) c2 sum += arr[i][j]; c3 c 1 + c 2 x ( N +1) + c 2 x N x ( N +1) + c 3 x N x N (n O(n 2 ) 7

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

View Full Document
Running time of various statements while-loop for-loop 8
Examples i = 0; hile (i<N) { while (i<N) { X=X+Y; // O(1) s lt m ster (X) O(N) j st an e ample result = mystery(X); // O(N), just an example. .. i++; // O(1) } ± The body of the while loop: O(N) ± Loop is executed: N times N x O(N) = O(N 2 ) 9

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

View Full Document
Examples (cont.’d) if (i<j) r ( i=0; i<N; i++ ) for ( i=0; i<N; i++ ) X = X+i; O(N) else X=0; O(1) ax ( O(N) O(1) ) = O (N) Max ( O(N), O(1) ) = O (N) 10
Asymptotic Notation ± O notation: asymptotic “less than”: ² f(n)=O(g(n)) implies: f(n) “ ” g(n) otation: asymptotic “greater than”: ± Ω notation: asymptotic greater than : ² f(n)= Ω (g(n)) implies: f(n) “ ” g(n) ± Θ notation: asymptotic “equality”: ² f(n)= Θ (g(n)) implies: f(n) “=” g(n) 11

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

View Full Document
Definition: O(g), at most order g Let f,g are functions R R . e say that t ost rder g : ± We say that f is at most order g , if: c , k : f ( x ) cg ( x ), x>k eyond some point function at most a ² Beyond some point k , function f is at most a constant c times g ( i.e., proportional to g ).” ± “f is at most order g ”, or “f is O( g ) ”, or f =O( g )” all just mean that f O( g ). ± Sometimes the phrase “at most” is omitted. 12
Big-O Visualization k 13

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

View Full Document
Points about the definition ± Note that f is O( g ) as long as any values of c and k exist that satisfy the definition. ± But: The particular c , k , values that make the statement true are not unique: Any larger value of c and/or k will also work. 14
Big-O” Proof Examples ± Show that 30 n +8 is O( n ). ² Show c , k : 30 n +8 cn, n > k . ± Let c= 31, k =8. Assume n > k =8. Then cn = 31 n = 30 n + n > 30 n +8, so 30 n +8 < cn .

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.

{[ snackBarMessage ]}

### Page1 / 83

lec16&amp;17 - Discrete Computation Structures CSE 2353...

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

View Full Document
Ask a homework question - tutors are online