Tutorial01 Analysis of Algorithms
Tutorial01 Analysis of Algorithms
Analysis of Algorithms
Lucia Moura
4) Prove that if d(n) is O(f(n)) and e(n) is O(g(n)), then d(n)+e(n) is O(f(n)
+g(n)).
1.1) Big-Oh of unique1 ?
1.2 Big-Oh of unique2?
1) Determine the big-Oh of unique1 and unique2; which algorithm is
more efficient?
Example 1 and Example 2
Example 3 and Example 4
Example 5
3) The number of operations executed by
Algorithms A and B is 40n2 and 2n3,
respectively. Determine n0 such that A is
better than B for all n>=n0.
4) Prove that if d(n) is O(f(n)) and e(n) is O(g(n)),
then d(n)+e(n) is O(f(n)+g(n)).
Extras exercises:
• https://www.geeksforgeeks.org/algorithms-gq/analysis-of-algorithms-
gq/
• Suggested questions: Questions: 6, 8, 9, 10;
• Tricky challenge: Question 5
Appendix:
Big-Oh, Big-Omega, Big-Theta
Big-Oh (upper bound)
• given two functions f(n) and g(n), we say that
f(n) is O(g(n))
if and only if there are positive constants
c and n0 such that
f(n) c g(n) for all n n0
c • g(n)
f(n)
n0
n 13
big-Omega. (lower bound)
f(n)
c • g(n)
n0
n
Theorem.
f(n) is (g(n)) <===> if f(n) O(g(n)) AND g(n) O(f(n))
Theorem.
f(n) is (g(n)) <===> if f(n) O(g(n)) AND f(n) (g(n))
15