Chapter 3-Algorithms
Chapter 3-Algorithms
DISCRETE MATHEMATICS
Chapter 3: Algorithms
3.1 Algorithms
➢ Example Algorithms
➢ Algorithmic Paradigms
3.2 Growth of Functions
➢ Big-O and other Notation
3.3 Complexity of Algorithms
❖Big-O Notation
❖Big-O Estimates for Important Functions
❖Big-Omega and Big-Theta Notation
❖ In both computer science and in mathematics, there are many times when we
care about how fast a function grows.
❖ In computer science, we want to understand how quickly an algorithm can
solve a problem as the size of the input grows.
❖ We can compare the efficiency of two different algorithms for solving the
same problem.
❖ We can also determine whether it is practical to use a particular algorithm
as the input grows.
❖ Two of the areas of mathematics where questions about the growth of
functions are studied are:
❖ Number theory (covered in Chapter 4)
is
❖ If f(x) is O(g(x)) and h(x) is larger than g(x) for all positive real
numbers, then f(x) is O(h(x)).
Example: Let
where are real numbers with an ≠0.
Then f(x) is O(xn).
Uses triangle inequality, an
Proof: |f(x)| = |anxn + an-1 xn-1 + ∙∙∙ + a1x1 + a1exercise
| in Section 1.8.
≤ |an|xn + |an-1| xn-1 + ∙∙∙ + |a1|x1 + |a1|
Assuming x > 1
= xn (|an| + |an-1| /x + ∙∙∙ + |a1|/xn-1 + |a1|/ xn)
≤ xn (|an| + |an-1| + ∙∙∙ + |a1|+ |a1|)
➢ Take C = |an| + |an-1| + ∙∙∙ + |a1|+ |a1| and k = 1. Then f(x)
is O(xn).
➢ The leading term anxn of a polynomial dominates its growth.
Copyright © Nahid Sultana 2020-2021 10/4/2023
Big-O Estimates for some Important
12
Functions
Example: Use big-O notation to estimate the sum of the first n
positive integers.
Solution:
Definition: Let f and g be functions from the set of integers or the set
of real numbers to the set of real numbers. The function
if and .
Theorem: Let
where are real numbers with an ≠0.
Then f(x) is of order xn (or Θ(xn)).
Example:
The polynomial is order of x5 (or Θ(x5)).