𝑛
= 𝑂(?
2
𝑛 )
•
Then,
?
1
𝑛
⋅ ?
2
𝑛
= 𝑂(?
1
𝑛
⋅ ?
2
(𝑛))
Example
?
𝑛
= (𝑛
3
+ 𝑛
2
+ 1)(𝑛
7
+ 𝑛
12
)
What is the time complexity of
?
𝑛
•
Let
?
1
𝑛
= (𝑛
3
+ 𝑛
2
+ 1)
,
?
2
𝑛
= (𝑛
7
+ 𝑛
12
)
–
?
1
𝑛
= 𝑂
𝑛
3
, ?
2
𝑛
= 𝑛
12
–
?
𝑛
= ?
1
𝑛
⋅ ?
2
𝑛
= 𝑂
𝑛
3
⋅ 𝑛
12
= 𝑂(𝑛
15
)
Product Rule
Complexity Analysis: Growth of Functions
14
The big multiple the big

CSCI2100C Data Structures
Sum
property
?
1
𝑛
= 𝑂
?
1
𝑛
, ?
2
𝑛
= 𝑂(?
2
𝑛 )
•
Then,
?
1
𝑛
+ ?
2
𝑛
= 𝑂
max(?
1
𝑛 , ?
2
𝑛
)
Example
?
𝑛
=
𝑛
3
+ 𝑛
2
+ 1 + (𝑛
4
+ 𝑛
7
+ 𝑛
20
+ 𝑛
30
)
?
1
=
𝑛
3
+ 𝑛
2
+ 1
,
?
2
=
𝑛
4
+ 𝑛
7
+ 𝑛
20
+ 𝑛
30
•
?
1
= 𝑂(𝑛
3
)
•
?
2
= 𝑂(𝑛
30
)
?
𝑛
= 𝑂
max(𝑛
3
, 𝑛
30
)
•
𝑂
𝑛
30
Big-Oh Rules (iii)
Complexity Analysis: Growth of Functions
15
The bigger of the two big

CSCI2100C Data Structures
We denote the number of basic operations of
each line as a function of n
?
1
𝑛 , ?
2
𝑛 , ⋯
LinearSearch: Using Sum Property
Complexity Analysis: Growth of Functions
16
LinearSearch(A, n, searchnum)
for
i = 0 to n -1
if
a
[i] =
searchnum
return
i
return
-1
1
2
3
4
2*n +2
2*n
1
1
Total:
4*n+4
?
1
𝑛
= 𝑂(𝑛)
?
2
𝑛
= 𝑂(𝑛)
?
3
𝑛
= 𝑂(1)
?
4
𝑛
= 𝑂(1)
𝑂
max(𝑛, 𝑛 , 1,1 ) = 𝑂(𝑛)

CSCI2100C Data Structures
What is wrong here?
.
Complexity Analysis: Growth of Functions
17

CSCI2100C Data Structures
Log functions grow slower than power functions.
lim
𝑛→∞
log 𝑛
?
𝑛
?
→ 0
, for
?, ? > 0
If
?
𝑛
=
log 𝑛
?
+ 𝑛
?
where
?, ? > 0,
Then
?(𝑛) = 𝑂(𝑛
?
)
.
If
?
𝑛
=
log 𝑛
?
+ ?
, where
?, ? > 0,
Then
?(𝑛) = 𝑂
log 𝑛
?
.
Example
?
𝑛
=
log 𝑛
2
+ 𝑛
0.0001
•
Let
? = 2, ? = 0.0001
•
𝑂(𝑛
0.0001
)
Big-Oh Rules (iv)
Complexity Analysis: Growth of Functions
18
log only beats constant

What is the time complexity of
?
2)What is the time complexity of

#### You've reached the end of your free preview.

Want to read all 27 pages?

- Fall '14
- Big O notation, Analysis of algorithms, Computational complexity theory