chapter 4
DESCRIPTION
Chapter 4. Analysis Tools. 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.1 Seven Functions. The Constant Function: f(n)= c, - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/1.jpg)
Zeinab Eid Algorithm Analysis 1
Chapter 4
Analysis Tools
![Page 2: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/2.jpg)
Zeinab Eid Algorithm Analysis 2
![Page 3: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/3.jpg)
Zeinab Eid Algorithm Analysis 3
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.
![Page 4: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/4.jpg)
Zeinab Eid Algorithm Analysis 4
4.1 Seven Functions
1. The Constant Function: f(n)= c,
where c is some fixed constant, c=5, c=100, or c=210, so we let g(n)=1, so f(n)=cg(n)
2. The Logarith Function: f(n)= logbn
x = logbn iff bx=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).
![Page 5: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/5.jpg)
Zeinab Eid Algorithm Analysis 5
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)= n2
It’s important for algorithms of nested loops.
6. The Cubic Function (Polynomial): f(n)= n3
f(n)=a0+a1n+ a2n2+…+adnd, is a polynomial of degree d,
where a0 , a1 ,…., ad are constants. 7. The Exponential Function: f(n)= bn
![Page 6: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/6.jpg)
Zeinab Eid Algorithm Analysis 6
![Page 7: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/7.jpg)
Zeinab Eid Algorithm Analysis 7
![Page 8: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/8.jpg)
Zeinab Eid Algorithm Analysis 8
![Page 9: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/9.jpg)
Zeinab Eid Algorithm Analysis 9
![Page 10: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/10.jpg)
Zeinab Eid Algorithm Analysis 10
![Page 11: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/11.jpg)
Zeinab Eid Algorithm Analysis 12
![Page 12: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/12.jpg)
Zeinab Eid Algorithm Analysis 13
![Page 13: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/13.jpg)
Zeinab Eid Algorithm Analysis 14
![Page 14: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/14.jpg)
Zeinab Eid Algorithm Analysis 15
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.
![Page 15: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/15.jpg)
Zeinab Eid Algorithm Analysis 16
![Page 16: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/16.jpg)
Zeinab Eid Algorithm Analysis 17
![Page 17: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/17.jpg)
Zeinab Eid Algorithm Analysis 18
Primitive Operations
![Page 18: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/18.jpg)
Zeinab Eid Algorithm Analysis 19
Counting Primitive Operations
![Page 19: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/19.jpg)
Zeinab Eid Algorithm Analysis 20
![Page 20: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/20.jpg)
Zeinab Eid Algorithm Analysis 21
![Page 21: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/21.jpg)
Zeinab Eid Algorithm Analysis 22
![Page 22: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/22.jpg)
Zeinab Eid Algorithm Analysis 23
4.2.3 Asymptotic Notation
![Page 23: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/23.jpg)
Zeinab Eid Algorithm Analysis 24
Example
![Page 24: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/24.jpg)
Zeinab Eid Algorithm Analysis 25
![Page 25: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/25.jpg)
Zeinab Eid Algorithm Analysis 26
![Page 26: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/26.jpg)
Zeinab Eid Algorithm Analysis 27
Properties of Big-Oh Notation
![Page 27: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/27.jpg)
Zeinab Eid Algorithm Analysis 28
![Page 28: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/28.jpg)
Zeinab Eid Algorithm Analysis 29
![Page 29: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/29.jpg)
Zeinab Eid Algorithm Analysis 30
![Page 30: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/30.jpg)
Zeinab Eid Algorithm Analysis 31
![Page 31: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/31.jpg)
Zeinab Eid Algorithm Analysis 32
![Page 32: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/32.jpg)
Zeinab Eid Algorithm Analysis 33
![Page 33: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/33.jpg)
Zeinab Eid Algorithm Analysis 34
Big-Omega and Big-Theta
![Page 34: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/34.jpg)
Zeinab Eid Algorithm Analysis 35
![Page 35: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/35.jpg)
Zeinab Eid Algorithm Analysis 36
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 n0 ≥ 1 such that:
f(n) ≥ cg(n), for n ≥ n0
![Page 36: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/36.jpg)
Zeinab Eid Algorithm Analysis 37
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 n0 ≥ 1 such that:
c’g(n) ≤ f(n) ≥ c”g(n), for n ≥ n0 .
![Page 37: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/37.jpg)
Zeinab Eid Algorithm Analysis 38
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)
![Page 38: Chapter 4](https://reader036.vdocuments.mx/reader036/viewer/2022070411/56814868550346895db57592/html5/thumbnails/38.jpg)
Zeinab Eid Algorithm Analysis 39