Presentation is loading. Please wait.

Presentation is loading. Please wait.

What is an Algorithm? Algorithm Specification.

Similar presentations


Presentation on theme: "What is an Algorithm? Algorithm Specification."— Presentation transcript:

1

2

3 What is an Algorithm?

4 Algorithm Specification

5

6

7 Asymptotic Notations Q, O, W

8 Asymptotic Notation Q(Theta)(Average Case)
O(Big-oh)(Worst Case)(Upper Bound) W(Best case)(Lower Bound)

9 -notation For function g(n), we define (g(n)), big-Theta of n, as the set: (g(n)) = {f(n) :  positive constants c1, c2, and n0, such that n  n0, we have 0  c1g(n)  f(n)  c2g(n) } f(n) and g(n) are nonnegative, for large n.

10 O-notation For function g(n), we define O(g(n)), big-O of n, as the set: O(g(n)) = {f(n) :  positive constants c and n0, such that n  n0, we have 0  f(n)  cg(n) } g(n) is an asymptotic upper bound for f(n).

11  -notation For function g(n), we define (g(n)), big-Omega of n, as the set: (g(n)) = {f(n) :  positive constants c and n0, such that n  n0, we have 0  cg(n)  f(n)} g(n) is an asymptotic lower bound for f(n).

12 Example 3n2 + 17 (1), (n), (n2)  lower bounds
O(n2), O(n3), ...  upper bounds (n2)  exact bound

13 Example for Practice Examples 3n+2=O(n) /* 3n+24n for n2 */
10n2+4n+2=O(n2) /* 10n2+4n+211n2 for n5 */ 6*2n+n2=O(2n) /* 6*2n+n2 7*2n for n4 */

14 Relations Between Q, O, W

15 Relations Between Q, W, O I.e., (g(n)) = O(g(n)) Ç W(g(n))
Theorem : For any two functions g(n) and f(n), f(n) = (g(n)) iff f(n) = O(g(n)) and f(n) = (g(n)). I.e., (g(n)) = O(g(n)) Ç W(g(n)) In practice, asymptotically tight bounds are obtained from asymptotic upper and lower bounds.

16 o-notation For a given function g(n), the set little-o:
o(g(n)) = {f(n):  c > 0,  n0 > 0 such that  n  n0, we have 0  f(n) < cg(n)}. f(n) becomes insignificant relative to g(n) as n approaches infinity: lim [f(n) / g(n)] = 0 n g(n) is an upper bound for f(n) that is not asymptotically tight.

17 ω-notation For a given function g(n), the set little-: ω
ω(g(n)) = {f(n):  c > 0,  n0 > 0 such that  n  n0, we have 0  cg(n) <f(n)}. f(n) becomes insignificant relative to g(n) as n approaches infinity: lim [f(n) / g(n)] = 0 n g(n) is an lower bound for f(n) that is not asymptotically tight.

18 Algorithm Definition An algorithm is a finite set of instructions that accomplishes a particular task. Criteria input output definiteness: clear and unambiguous finiteness: terminate after a finite number of steps effectiveness: instruction is basic enough to be carried out

19 Measurements Criteria Performance Analysis (machine independent)
Is it correct? Is it readable? Performance Analysis (machine independent) space complexity: storage requirement time complexity: computing time Performance Measurement (machine dependent)

20 Space Complexity S(P)=C+SP(I)
Fixed Space Requirements (C) Independent of the characteristics of the inputs and outputs instruction space space for simple variables, fixed-size structured variable, constants Variable Space Requirements (SP(I)) depend on the instance characteristic I number, size, values of inputs and outputs associated with I recursive stack space, formal parameters, local variables, return address

21 O(1): constant O(n): linear O(n2): quadratic O(n3): cubic O(2n): exponential O(logn) O(nlogn)

22 Function values

23 Plot of function values
nlogn n logn

24 Times on a 1 billion instruction per second computer


Download ppt "What is an Algorithm? Algorithm Specification."

Similar presentations


Ads by Google