Вы находитесь на странице: 1из 3

CS502-Fundamentals of Algorithms

Lecture No.06

Lecture No.6 Asymptotic Notation


You may be asking that we continue to use the notation () but have never defined it. Lets remedy this now. Given any function g(n), we define (g(n)) to be a set of functions that asymptotically equivalent to g(n). Formally:

This is written as f(n) (g(n)) That is, f(n) and g(n) are asymptotically equivalent. This means that they have essentially the same growth rates for large n. For example, functions like 4n2, (8n2 + 2n - 3), (n2/5 + n - 10 log n) n(n - 3)

are all asymptotically equivalent. As n becomes large, the dominant (fastest growing) term is some constant times n2. Consider the function f(n) = 8n2 + 2n 3 Our informal rule of keeping the largest term and ignoring the constant suggests that f(n) (n2). Lets see why this bears out formally. We need to show two things for f(n) = 8n2 + 2n 3 Lower bound f(n) = 8n2 + 2n - 3 grows asymptotically at least as fast as n2, Upper bound f(n) grows no faster asymptotically than n2, Lower bound: f(n) grows asymptotically at least as fast as n2. For this, need to show that there exist positive constants c1 and n0, such that f(n) c1n2 for all n n0. Consider the reasoning f(n) = 8n2 + 2n - 3 _ 8n2 - 3 = 7n2 + (n2 - 3) 7n2

Page 1 Copyright Virtual University of Pakistan

of 3

CS502-Fundamentals of Algorithms

Lecture No.06

Thus c1 = 7. We implicitly assumed that 2n 0 and n2 - 3 0 these are not true for all n but if n 3, then both are true. So select n0 3. We then have f(n) c1 n2 for all n n0. Upper bound: f(n) grows asymptotically no faster than n2. For this, we need to show that there exist positive constants c2 and n0, such that f(n) c2n2 for all n n0. Consider the reasoning f(n) = 8n2 + 2n - 3 8n2 + 2n 8n2 + 2n2 = 10n2 Thus c2 = 10. We implicitly made the assumption that 2n 2n2. This is not true for all n but it is true for all n 1 So select n0 1. We thus have f(n) c2n2 for all n n0 . From lower bound we have n0 3. From upper bound we have n0 1. Combining the two, we let n0 be the larger of the two: n0 3. In conclusion, if we let c1 = 7, c2 = 10 and n0 3, we have 7n2 8n2 + 2n - 3 10n2 for all n 3 We have thus established 0 c1g(n) f(n) c2g(n) for all n n0 Here are plots of the three functions. Notice the bounds.

0 2e+104e+10

Figure 2.1: Asymptotic Notation Example

We have established that f(n) n2. Lets show why f(n) is not in some other asymptotic class. First, lets show that f(n) (n). Show that f(n) (n). If this were true, we would have had to satisfy both the upper and lower bounds. The lower bound is
Page 2 Copyright Virtual University of Pakistan

of 3

CS502-Fundamentals of Algorithms

Lecture No.06

satisfied because f(n) = 8n2 + 2n - 3 does grow at least as fast asymptotically as n. But the upper bound is false. Upper bounds requires that there exist positive constants c2 and n0 such that f(n) c2n for all n n0.

Page 3 Copyright Virtual University of Pakistan

of 3

Вам также может понравиться