Download presentation
Presentation is loading. Please wait.
1
Growth of Functions
2
Growth of Functions How the running time of an algorithm increases with the size of the input in the limit, as the size of the input increases without bound. The running-time function T(n) which usually is defined only on integer input sizes.
3
Properties of Growth-Rate Functions
We can ignore low-order terms in an algorithm’s growth-rate function. •If an algorithm is O(n3+4n2+3n), it is also O(n3). •We only use the higher-order term as algorithm’s growth-rate function. 2.We can ignore a multiplicative constant in the higher-order term of an algorithm’s growth-rate function. •If an algorithm is O(5n3), it is also O(n3). 3.O(f(n)) + O(g(n)) = O(f(n)+g(n)) •We can combine growth-rate functions. •If an algorithm is O(n3) + O(4n2), it is also O(n3 +4n2)So, it is O(n3). •Similar rules hold for multiplication.
4
Problems with growth rate analysis
An algorithm with a smaller growth rate will only run faster than one with a higher growth rate for any particular n, when n is ‘large enough’ otherwise NOT. •Algorithms with identical growth rates may have strikingly different running times because of the constants in the running time functions. •The value of n where two growth rates are the same is called the break-even point.
7
Asymptotic Notations
8
𝜃-notation For a given function g(n) ,we denote by ᶿ(g(n)) the set of functions 𝜃 -notation bounds a function to within constant factors. We write f(n) = ᶿ(g(n)) if there exist positive constants n0, c1, and c2 such that at and to the right of n0, the value of f(n) always lies between c1g(n) and c2g(n) inclusive. For all values of n at and to the right of n0, the value of f (n) lies at or above c1g(n) and at or below c2g(n). In other words, for all n n0, the function f (n) is equal to g(n) to within a constant factor. We say that g(n) is an asymptotically tight bound for f(n).
9
o-notation For all values n at and to the right of n0, the value of the function f (n) is on or below cg(n). We say that g(n) is an asymptotically upper bound for f(n).
10
Ω-notation For all values n at or to the
right of n0, the value of f(n) is on or above cg(n). We say that g(n) is an asymptotically lower bound for f(n).
11
𝜽( g(n)) ⊆ O(g(n)) 𝜽 -notation is a stronger notion than O-notation.
Written set-theoretically, we have 𝜽( g(n)) ⊆ O(g(n))
12
Definition of the Orders of an Algorithm
13
Definition of the Orders of an Algorithm
14
Definition of the Orders of an Algorithm
16
Shortcomings of asymptotic analysis
In practice, other considerations beside asymptotic analysis are important when choosing between algorithms. Sometimes, an algorithm with worse asymptotic behavior is preferable. For the sake of this discussion, let algorithm A be asymptotically better than algorithm B. Here are some common issues with algorithms that have better asymptotic behavior: •Implementation complexity Algorithms with better complexity are often (much) more complicated. This can increase coding time and the constants. •Small input sizes Asymptotic analysis ignores small input sizes. At small input sizes, constant factors or low order terms could dominate running time, causing B to outperform A. •Worst case versus average performance If A has better worst case performance than B, but the average performance of B given the expected input is better, then B could be a better choice than A. Conversely, if the worst case performance of B is unacceptable (say for life-threatening or mission-critical reasons), A must still be used.
17
Reflexivity Relations over , , O
Example 1 Since, 0 f(n) cf(n) n n0 = 1, if c = 1 Hence f(n) = O(f(n)) Example 2 Since, 0 cf(n) f(n) n n0 = 1, if c = 1 Hence f(n) = (f(n)) Example 3 Since, 0 c1f(n) f(n) c2f(n) n n0 = 1,if c1= c2 = 1 Hence f(n) = (f(n)) Note: All the relations, Q, W, O, are reflexive
18
f(n) = (g(n)) g(n) = (f(n))
Symmetry over Property : prove that f(n) = (g(n)) g(n) = (f(n)) Proof Since f(n) = (g(n)) i.e. f(n) (g(n)) constants c1, c2 > 0 and n0 N such that 0 c1g(n) f(n) c2g(n) n n0 (1) (1) 0 c1g(n) f(n) c2g(n) 0 f(n) c2g(n) 0 (1/c2)f(n) g(n) (2) (1) 0 c1g(n) f(n) c2g(n) 0 c1g(n) f(n) 0 g(n) (1/c1)f(n) (3)
19
Big O, big omega , do not satisfy the symmetry property.
Symmetry over Q From (2),(3): 0 (1/c2)f(n) g(n) 0 g(n) (1/c1)f(n) 0 (1/c2)f(n) g(n) (1/c1)f(n) Suppose that 1/c2 = c3, and 1/c1 = c4, Now the above equation implies that 0 c3f(n) g(n) c4f(n), n n0 g(n) = (f(n)), n n0 Hence it proves that, f(n) = (g(n)) g(n) = (f(n)) Big O, big omega , do not satisfy the symmetry property.
20
Transitivity Relation over Q, W, O, o and
Prove the following f(n) = (g(n)) & g(n) = (h(n)) f(n) = (h(n)) f(n) = O(g(n)) & g(n) = O(h(n)) f(n) = O(h(n)) f(n) = (g(n)) & g(n) = (h(n)) f(n) = (h(n)) Note It is to be noted that all these algorithms complexity measuring notations are in fact relations which satisfy the transitive property.
21
Transitivity Relation over Q
Property 1 f(n) = (g(n)) & g(n) = (h(n)) f(n) = (h(n)) Proof Since f(n) = (g(n)) i.e. f(n) (g(n)) constants c1, c2 > 0 and n01 N such that 0 c1g(n) f(n) c2g(n) n n01 (1) 2. Now since g(n) = (h(n)) i.e. g(n) (h(n)) constants c3, c4 > 0 and n02 N such that 0 c3h(n) g(n) c4h(n) n n02 (2) 3. Now let us suppose that n0 = max (n01, n02)
22
Transitivity Relation over Q
4. Now we have to show that f(n) = (h(n)) i.e. we have to prove that constants c5, c6 > 0 and n0 N such that 0 c5h(n) f(n) c6h(n) ? (2) 0 c3h(n) g(n) c4h(n) 0 c3h(n) g(n) (3) 0 c1g(n) f(n) c2g(n) 0 c1g(n) f(n) 0 g(n) (1/c1)f(n) (4) From (3) and (4), 0 c3h(n) g(n) (1/c1)f(n) 0 c1c3h(n) f(n) (5)
23
Transitivity Relation over Q
(1) 0 c1g(n) f(n) c2g(n) 0 f(n) c2g(n) 0 (1/c2)f(n) g(n) (6) (2) 0 c3h(n) g(n) c4h(n) 0 g(n) c4h(n) (7) From (6) and (7), 0 (1/c2)f(n) g(n) (c4)h(n) 0 (1/c2)f(n) (c4)h(n) 0 f(n) c2c4h(n) (8) From (5), (8), 0 c1c3h(n) f(n) 0 f(n) c2c4h(n) 0 c1c3h(n) f(n) c2c4h(n) 0 c5h(n) f(n) c6h(n) And hence f(n) = (h(n)) n n0
24
Transitivity Relation over Big O
Property 2 f(n) = O(g(n)) & g(n) = O(h(n)) f(n) = O(h(n)) Proof Since f(n) = O(g(n)) i.e. f(n) O(g(n)) constants c1 > 0 and n01 N such that 0 f(n) c1g(n) n n01 (1) 2. Now since g(n) = O(h(n)) i.e. g(n) O(h(n)) constants c2 > 0 and n02 N such that 0 g(n) c2h(n) n n02 (2) 3. Now let us suppose that n0 = max (n01, n02)
25
Transitivity Relation over Big O
Now we have to two equations 0 f(n) c1g(n) n n01 (1) 0 g(n) c2h(n) n n02 (2) (2) 0 c1g(n) c1c2h(n) n n02 (3) From (1) and (3) 0 f(n) c1g(n) c1c2h(n) Now suppose that c3= c1c2 0 f(n) c1c2h(n) And hence f(n) = O(h(n)) n n0
26
Transitivity Relation over Big
Property 3 f(n) = (g(n)) & g(n) = (h(n)) f(n) = (h(n)) Proof Since f(n) = (g(n)) constants c1 > 0 and n01 N such that 0 c1g(n) f(n) n n01 (1) 2. Now since g(n) = (h(n)) constants c2 > 0 and n02 N such that 0 c2h(n) g(n) n n02 (2) 3. Suppose that n0 = max (n01, n02)
27
Transitivity Relation over Big
4. We have to show that f(n) = (h(n)) i.e. we have to prove that constants c3 > 0 and n0 N such that 0 c3h(n) f(n) n n0 ? (2) 0 c2h(n) g(n) (1) 0 c1g(n) f(n) 0 g(n) (1/c1)f(n) (3) From (2) and (3), 0 c2h(n) g(n) (1/c1)f(n) 0 c1c2h(n) f(n) hence f(n) = (h(n)), n n0
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.