Professional Documents
Culture Documents
Georgy Gimel’farb
1 / 15
Outline Complexity Basic tools Big-Oh Big Omega Big Theta Examples
1 Complexity
2 Basic tools
3 Big-Oh
4 Big Omega
5 Big Theta
6 Examples
2 / 15
Outline Complexity Basic tools Big-Oh Big Omega Big Theta Examples
3 / 15
Outline Complexity Basic tools Big-Oh Big Omega Big Theta Examples
4 / 15
Outline Complexity Basic tools Big-Oh Big Omega Big Theta Examples
f (n)
Relative Growth g(n) = f (5) of Running Time
The approximate running time for large input sizes gives enough
information to distinguish between a good and a bad algorithm.
Input size n
Function f (n) 5 52 = 25 53 = 125 54 = 625
Constant 1 1 1 1 1
Q
Logarithmic log5 n 1 2 3 4
Q
Linear n 1 5 25 125
Q
Linearithmic n log5 n 1 10 75 500
Q
Quadratic n2 1 52 = 25 54 = 625 56 = 15, 625
Q
Cubic n3 1 53 = 125 56 = 15, 625 59 = 1, 953, 125
Q
Exponential 2n 1 220 ≈ 106 2120 ≈ 1036 2620 ≈ 10187
5 / 15
Outline Complexity Basic tools Big-Oh Big Omega Big Theta Examples
6 / 15
Outline Complexity Basic tools Big-Oh Big Omega Big Theta Examples
7 / 15
Outline Complexity Basic tools Big-Oh Big Omega Big Theta Examples
8 / 15
Outline Complexity Basic tools Big-Oh Big Omega Big Theta Examples
8 / 15
Outline Complexity Basic tools Big-Oh Big Omega Big Theta Examples
9 / 15
Outline Complexity Basic tools Big-Oh Big Omega Big Theta Examples
9 / 15
Outline Complexity Basic tools Big-Oh Big Omega Big Theta Examples
9 / 15
Outline Complexity Basic tools Big-Oh Big Omega Big Theta Examples
• If g(n) is Θ(f (n)) then g(n) is O(f (n)) and f (n) is O(g(n))
or, what is the same, g(n) is O(f (n)) and g(n) is Ω(f (n)):
• g(n) is O(f (n)) → g(n) ≤ c0 f (n) for n > n0 .
• g(n) is Ω(f (n)) → f (n) ≤ c00 g(n) for n > n00 .
• g(n) is Θ(f (n)) ← c00 = c1 ; c0 = c2 , and n0 = max{n0 , n00 }.
1
10 / 15
Outline Complexity Basic tools Big-Oh Big Omega Big Theta Examples
• If g(n) is Θ(f (n)) then g(n) is O(f (n)) and f (n) is O(g(n))
or, what is the same, g(n) is O(f (n)) and g(n) is Ω(f (n)):
• g(n) is O(f (n)) → g(n) ≤ c0 f (n) for n > n0 .
• g(n) is Ω(f (n)) → f (n) ≤ c00 g(n) for n > n00 .
• g(n) is Θ(f (n)) ← c00 = c1 ; c0 = c2 , and n0 = max{n0 , n00 }.
1
10 / 15
Outline Complexity Basic tools Big-Oh Big Omega Big Theta Examples
• If g(n) is Θ(f (n)) then g(n) is O(f (n)) and f (n) is O(g(n))
or, what is the same, g(n) is O(f (n)) and g(n) is Ω(f (n)):
• g(n) is O(f (n)) → g(n) ≤ c0 f (n) for n > n0 .
• g(n) is Ω(f (n)) → f (n) ≤ c00 g(n) for n > n00 .
• g(n) is Θ(f (n)) ← c00 = c1 ; c0 = c2 , and n0 = max{n0 , n00 }.
1
10 / 15
Outline Complexity Basic tools Big-Oh Big Omega Big Theta Examples
11 / 15
Outline Complexity Basic tools Big-Oh Big Omega Big Theta Examples
T (n) = 108 + n
T (n) = 3n + 1
O(n)-time: −8
T (n) = 50 + 10 n T (n) = 106 n + 1
• Remember that “Big-Oh”, as well as “Big-Omega” and
“Big-Theta”, describes an asymptotic behaviour for
large problem sizes.
• Only the dominant terms as n → ∞ need to be shown as the
argument of “Big-Oh”, “Big-Omega”, and “Big-Theta”.
12 / 15
Outline Complexity Basic tools Big-Oh Big Omega Big Theta Examples
O(nm ); m ≥ k
13 / 15
Outline Complexity Basic tools Big-Oh Big Omega Big Theta Examples
O(nm ); m ≥ k
13 / 15
Outline Complexity Basic tools Big-Oh Big Omega Big Theta Examples
14 / 15
Outline Complexity Basic tools Big-Oh Big Omega Big Theta Examples
For each m > 1, the logarithmic function g(n) = logm (n) has the
same rate of increase as lg(n), i.e. log2 n, because
logm (n) = logm (2) lg(n) for all n > 0.
You will find later that the most efficient search for data in an
ordered array has logarithmic time complexity.
15 / 15