0% found this document useful (0 votes)
10 views15 pages

Chapter 2 - Asymptotic Notations

Uploaded by

bakersamer03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views15 pages

Chapter 2 - Asymptotic Notations

Uploaded by

bakersamer03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 15

Analysis of Algorithms

Course No.: 0602302


Asymptotic Notations

• A way to describe behavior of functions in the limit


– How we indicate running times of algorithms

– Describe the running time of an algorithm as n grows to 

• O notation: asymptotic “less than”: f(n) “≤”

g(n)

  notation: asymptotic “greater than”: f(n) “≥” g(n)

  notation: asymptotic “equality”: f(n) “=” g(n)


2
Logarithms
• In algorithm analysis we often use the notation “log n”
without specifying the base

Binary logarithm lg n log2 n log x y  y log x


Natural logarithm ln n loge n log xy  log x  log y
x
lg k n (lg n ) k log  log x  log y
y
lg lg n lg(lg n )
loga x  loga b logb x

a logb x  x logb a

3
Asymptotic Notations - Examples
• For each of the following pairs of functions, either f(n) is
O(g(n)), f(n) is Ω(g(n)), or f(n) = Θ(g(n)). Determine
which relationship is correct.
– f(n) = log n2; g(n) = log n + 5 f(n) =  (g(n))
– f(n) = n; g(n) = log n2 f(n) = (g(n))
– f(n) = log log n; g(n) = log n f(n) = O(g(n))
– f(n) = n; g(n) = log2 n f(n) = (g(n))
– f(n) = n log n + n; g(n) = log nf(n) = (g(n))
– f(n) = 10; g(n) = log 10 f(n) = (g(n))
– f(n) = 2n; g(n) = 10n2 f(n) = (g(n))
– f(n) = 2n; g(n) = 3n f(n) = O(g(n))
4
Asymptotic notations
• O-notation

• Intuitively: O(g(n)) = the set of


functions with a smaller or
same order of growth as g(n)

5
Examples

– 2n2 = O(n2n
3 2 ≤ cn3  2 ≤ cn  c = 1 and n = 2
): 0

n22):≤ cn2  c ≥ 1  c = 1 and n0= 1


– n2 = O(n

– 1000n2+1000n = O(n2):

1000n2+1000n ≤ cn2 ≤ cn2+ 1000n  c=1001 and n0 = 1

n ≤
– n = O(n ):
2 cn 2
 cn ≥ 1  c = 1 and n0= 1

6
• 2n2 = O(n3)

• 2n2 <= c.n3. divided by n2


• 2 <= c. n ,
• n=2. 2 <=c so c=1

7
Asymptotic notations (cont.)
  - notation

• Intuitively: (g(n)) = the set of


functions with a larger or same
order of growth as g(n)

8
Examples
– 5n2 = (n)
 cn
 c, n0 such that: 0  cn  5n 2  5n2 c = 1 and n0 = 1

– 100n + 5 ≠ (n2)
 c, n0 such that: 0  cn2  100n + 5
100n + 5  100n + 5n ( n  1) = 105n
cn2  105n
 n(cn – 105)  0
 n  105/c
Since n is positive  cn – 105  0
 contradiction: n cannot be smaller than a constant

– n = (2n), n3 = (n2), n = (logn)


9
• 5n2 = (n)

• C. n <= 5n2, divided both parts by n


• c<= 5.n
• c = 1 and n0 = 1

10
Asymptotic notations (cont.)
 -notation

• Intuitively (g(n)) = the set of


functions with the same order of
growth as g(n)

11
Examples
– n2/2 –n/2 = (n2)

• ½ n2 - ½ n ≤ ½ n2 n ≥ 0  c2= ½

• ½ n2 - ½ n ≥ ½ n2 - ½ n * ½ n ( n ≥ 2 ) = ¼ n2 

c1= ¼

– n ≠ (n2): c1 n2 ≤ n ≤ c2 n2

 only holds for: n ≤ 1/c1


12
• n2/2 –n/2 = (n2)
• c1n2 <= n2/2 –n/2 <= c2n2.

• c1n2 <= n2/2 –n/2. and n2/2 –n/2 <= c2n2

Start with the left Then right inequality


inequality n2/2 –n/2 <= c2n2
c1n2 <= n2/2 –n/2 ½-1/2n <=c2
c1 <= ½-1/2n
n=1 c1 <= 0
n=2. c1 <= ½-1/4=1/4

13
Examples
– 6n3 ≠ (n2): c1 n2 ≤ 6n3 ≤ c2 n2

 only holds for: n ≤ c2 /6

– n ≠ (logn): c1 logn ≤ n ≤ c2 logn

 c2 ≥ n/logn,  n≥ n0 – impossible

14
• n ≠ (logn)

15

You might also like