You are on page 1of 18

ALGORITHMS and

INTEGERS
(ECE 314 Discrete Mathematics)
By: ENGR. JANRY V. GARCIA
Objectives:
Demonstrate an understanding of relations and functions and be able to
determine their properties.
Demonstrate comprehension of discrete structures and their relevance in the
areas of data structures and algorithms, in particular.
• Growth of Functions
• Complexity of Algorithms
• Number Theory
Brief History and Definition
• Algorithms-(Abu Ja ’far Mohammed Ibin Musa Al-Khowarizmi, 780-850)
Brief History and Definition
• An algorithm is a finite set of precise instructions for performing a
computation or for solving a problem.
• Example: Describe an algorithm for finding the maximum value in a finite
sequence of integers.
Brief History and Definition
Description of algorithms in pseudocode:
• Intermediate step between English prose and formal coding in a
programming language.
• Focus on the fundamental operation of the program, instead of peculiarities
of a given programming language.
• Analyze the time required to solve a problem using an algorithm,
independent of the actual programming language.
Brief History and Definition
• Properties of Algorithms
Input: An algorithm has input values from a specified set.
Output: From the input values, the algorithm produces the output values from a specified set. The
output values are the solution.
Correctness: An algorithm should produce the correct output values for each set of input values.
Finiteness: An algorithm should produce the output after a finite number of steps for any input.
Effectiveness: It must be possible to perform each step of the algorithm correctly and in a finite
amount of time.
Generality: The algorithm should work for all problems of the desired form.
Growth of Function
Given functions f : N → R or f : R → R.
Analyzing how fast a function grows.
• Comparing two functions.
• Comparing the efficiently of different algorithms that solve the same
problem.
• Applications in number theory and combinatorics.
Growth of Function
• Sequence of Growth
O(1)….𝑙𝑜𝑔2 𝑛 … 𝑛 … 𝑛𝑙𝑜𝑔2 𝑛 … 𝑛2 … 2𝑛 … 𝑛!
Say n= 10
1…3.32…10…33.22…100…1024…3, 628, 800
Growth of Function
Growth of Function
Problem
Design and Analysis of
Program i.e., C programming Algorithm:
- Time
- Memory
P1

...
A1 A2 A3 A4 A(n)
Growth of Function
• Asymptotic Notations:
1. Big (Oh) - O t
C g(n) 𝑓(𝑛) ≤ 𝐶𝑔(𝑛)
f(n) 𝑛 ≥ 𝑛0
𝐶 > 0, 𝑛0 ≥ 1
𝑓 𝑛 = 𝑂(𝑔 𝑛 )

n
n0
Growth of Function
2. Big Omega - Ω
f(n)
t
𝑓(𝑛) ≥ 𝐶𝑔(𝑛)
C g(n)
𝑛 ≥ 𝑛0
𝐶 > 0, 𝑛0 ≥ 1
𝑓 𝑛 = Ω(𝑔 𝑛 )

n
n0
Growth of Function
3. Big Theta - 𝜃
t
C2 g(n) 𝑓 𝑛 = 𝜃𝑔(𝑛)
f(n) 𝐶1𝑔(𝑛) ≤ 𝑓(𝑛) ≤ 𝐶2𝑔(𝑛)

𝐶1, 𝐶2 > 0, 𝑛 ≥ 𝑛0
C1 g(n)
𝑛0 ≥ 1

n
n0
Growth of Function
• O-worst case
• Ω-best case
• 𝜃- average case
Example: 5 7 1 2 4 10 20 11 (linear search)
Ω(1)
𝑂(𝑛)
𝑛
𝜃 = 𝜃(𝑛)
2
Growth of Function
Growth of Function
Growth of Functions

𝑇(𝑛)
lim
𝑛→∞ 𝑓(𝑛)

C(>0) ∞
0

𝑇 𝑛 =𝑂 𝑓 𝑛
𝑇 𝑛 = 𝑂(𝑓 𝑛 ) 𝑇 𝑛 = Ω(𝑓 𝑛 )
𝑇 𝑛 = Ω(𝑓 𝑛 )
𝑇 𝑛 = 𝜃(𝑓 𝑛 )
Growth of Functions
• Let f(x)>0, g(x)> 0 for all x≥ 𝑟 where r is some real number
𝑓(𝑥)
• If lim = ∞, f(x) is going to infinity more quickly
𝑛→∞ 𝑔(𝑥)
𝑓(𝑥)
• If lim = 0, g(x) is going to infinity more quickly
𝑛→∞ 𝑔(𝑥)
𝑓(𝑥)
• If lim = 𝑘, f(x) is going to infinity ‘k’ times as quickly as g(x)
𝑛→∞ 𝑔(𝑥)

You might also like