Presentation is loading. Please wait.

Presentation is loading. Please wait.

Zeinab EidAlgorithm Analysis1 Chapter 4 Analysis Tools.

Similar presentations


Presentation on theme: "Zeinab EidAlgorithm Analysis1 Chapter 4 Analysis Tools."— Presentation transcript:

1 Zeinab EidAlgorithm Analysis1 Chapter 4 Analysis Tools

2 Zeinab EidAlgorithm Analysis2

3 Zeinab EidAlgorithm Analysis3 Why we Analyze Algorithms We try to save computer resources such as:  Memory space used to store data structures, Space Complexity  CPU time, which is reflected by Algorithm Run Time Complexity.

4 Zeinab EidAlgorithm Analysis4 4.1 Seven Functions 1.The Constant Function: f(n)= c, where c is some fixed constant, c=5, c=100, or c=2 10, so we let g(n)=1, so f(n)=cg(n) 2.The Logarith Function: f(n)= log b n x = log b n iff b x =n, (see Proposition 4.1), the most common base for logarithmic function in computer science is 2. 3.Linear Function: f(n)= n, important for algorithms on vectors (one dim. Arrays).

5 Zeinab EidAlgorithm Analysis5 4.The N-Log-N Function: f(n)= nlogn This function grows a little faster than linear function and a lot slower than quadratic function. 5.The Quadratic Function: f(n)= n 2 It’s important for algorithms of nested loops. 6.The Cubic Function (Polynomial): f(n)= n 3 f(n)=a 0 +a 1 n+ a 2 n 2 +…+a d n d, is a polynomial of degree d, where a 0, a 1,…., a d are constants. 7.The Exponential Function: f(n)= b n

6 Zeinab EidAlgorithm Analysis6

7 Zeinab EidAlgorithm Analysis7

8 Zeinab EidAlgorithm Analysis8

9 Zeinab EidAlgorithm Analysis9

10 Zeinab EidAlgorithm Analysis10

11 Zeinab EidAlgorithm Analysis11 4.2.2 Primitive Operations If we wish to analyze

12 Zeinab EidAlgorithm Analysis12

13 Zeinab EidAlgorithm Analysis13

14 Zeinab EidAlgorithm Analysis14

15 Zeinab EidAlgorithm Analysis15 We define a set of primitive operations such as the following: Assigning a value to a variable Calling a method Performing an arithmetic operation (for example, adding two numbers) Comparing two numbers Indexing into an array Following an object reference Returning from a method.

16 Zeinab EidAlgorithm Analysis16

17 Zeinab EidAlgorithm Analysis17

18 Zeinab EidAlgorithm Analysis18 Primitive Operations

19 Zeinab EidAlgorithm Analysis19 Counting Primitive Operations

20 Zeinab EidAlgorithm Analysis20

21 Zeinab EidAlgorithm Analysis21

22 Zeinab EidAlgorithm Analysis22

23 Zeinab EidAlgorithm Analysis23 4.2.3 Asymptotic Notation

24 Zeinab EidAlgorithm Analysis24 Example

25 Zeinab EidAlgorithm Analysis25

26 Zeinab EidAlgorithm Analysis26

27 Zeinab EidAlgorithm Analysis27 Properties of Big-Oh Notation

28 Zeinab EidAlgorithm Analysis28

29 Zeinab EidAlgorithm Analysis29

30 Zeinab EidAlgorithm Analysis30

31 Zeinab EidAlgorithm Analysis31

32 Zeinab EidAlgorithm Analysis32

33 Zeinab EidAlgorithm Analysis33

34 Zeinab EidAlgorithm Analysis34 Big-Omega and Big-Theta

35 Zeinab EidAlgorithm Analysis35

36 Zeinab EidAlgorithm Analysis36 Big-Omega Just as Big-Oh notation provides us a way of saying that a function f(n) is “less than or equal to” another function, Big-Omega notation provides us a way of saying that a function f(n) is “greater than or equal to” another function. Let f(n) and g(n) be functions mapping non- negative integers: We say that f(n) is Ω(g(n)) if g(n) is O(f(n)) That’s there is a real constant c>0 and an integer constant n 0 ≥ 1 such that: f(n) ≥ cg(n), for n ≥ n 0

37 Zeinab EidAlgorithm Analysis37 Big-Theta In addition, there is a notation that allows us to say that two functions grow at the same rate, up to a constant factor. We say that f(n) is Θ(g(n)) if f(n) is O(g(n)) and f(n) is Ω(g(n)), That’s, there are real constants c’>0 and c”>0 and an integer constant n 0 ≥ 1 such that: c’g(n) ≤ f(n) ≥ c”g(n), for n ≥ n 0.

38 Zeinab EidAlgorithm Analysis38 Example f(n) = 3nlog n + 4n + 5log n is Θ(nlog n) Since 3nlog n + 4n + 5log n ≥ 3nlog n for n ≥2 So, f(n) is Ω(nlog n) Since 3nlog n + 4n + 5log n ≤ (3+4+5)nlog n for n ≥2 So, f(n) is O(nlog n) Thus, f(n) is Θ(nlog n)

39 Zeinab EidAlgorithm Analysis39


Download ppt "Zeinab EidAlgorithm Analysis1 Chapter 4 Analysis Tools."

Similar presentations


Ads by Google