01Chapter-One Introduction To Analysis of Algorithm
01Chapter-One Introduction To Analysis of Algorithm
01Chapter-One Introduction To Analysis of Algorithm
Introduction to Analysis of
Algorithm
Basic Topics of Chapter- One
Introduction to Algorithm
Characteristics algorithms
What is Analysis of algorithm.
Why Analyse an Algorithm?
Asymptotic Notations
What is algorithm?
An algorithm is:
should not run for infinity, i.e., an algorithm must end at some point
problem.
efficient.
Problem definition
Specification of an Algorithm
Designing an Algorithm
Analysis of an Algorithm
Implementation of an Algorithm
Program testing
Documentation
Exercise #1
1. What is Pseudocode ?
2. What are the difference between Algorithm and Pseudo-code
3. Write an algorithms for the following questions
a) Roots of a quadratic equation ax2 + bx + c = 0
b) Check whether a number is a prime number or not
c) find the largest number among three different numbers
Analysis of algorithms
In theoretical analysis of algorithms, it is common to estimate their
complexity in the asymptotic sense, i.e., to estimate the complexity
function for arbitrarily large input.
The term "analysis of algorithms" was coined by Donald Knuth.
Algorithm analysis is an important part of computational
complexity theory, which provides theoretical estimation for the
required resources of an algorithm to solve a specific computational
problem.
Most algorithms are designed to work with inputs of arbitrary
length.
Analysis of algorithms…
(both immediate and auxiliary) to hold the program and its data.
skill.
Why Analysis of Algorithm
For example, we know that a set of numbers can be sorted using different
algorithms.
for the same input. Hence, time complexity of those algorithms may
differ.
each algorithm.
The Need for Analysis…
algorithm.
"Time" can mean the number of memory accesses performed, the number of
comparisons between integers, the number of times some inner loop is executed,
or some other natural unit related to the amount of real time the algorithm will
take.
ii. Space Complexity
O (n) notation.
Many algorithms have inputs that can vary in size, e.g., an array.
In such cases, the space complexity will depend on the size of the input and
hence, cannot be less that O(n) for an input of size n.
For fixed-size inputs, the complexity will be a constant O(1).
Asymptotic Notations
Note: Some examples of functions i.e. which function is smaller than the other
(Order of notations)as follows:
Solution:
f(n)=2n+3
2n+3≤ 5 n , n≥1
f(n) c g(n)
therefore f(n)= O(n)
A. f(n)=O()
B. f(n)=O(n)
C. f(n)= O()
D. f(n)=O(logn)
ii. Ω( Big omega) notations
Lower bound (at least) i.e. minimum time complexity (Best case time
complexity)
Definition: The function 𝒇(𝒏) = 𝛀(𝐠(𝒏)) if there exists positive
constants c and no such that 𝒇(𝒏) ≥ 𝒄. 𝒈(𝒏) for 𝒏 ≥ 𝒏𝟎 in all case
i.e. f(n)=𝛀().
iii. Ɵ(Big theta) notations
To denote asymptotic tight bound
Average case time complexity
The function 𝑓(𝑛) = Ɵ(g(𝑛)) if there exist positive constants c1, c2
and no. Such that 𝑐1. 𝑔(𝑛) ≤ 𝑓(𝑛) ≤ 𝑐2. 𝑔(𝑛) 𝒏 ≥ 𝒏𝟎 in all case
To the write of no the value of f(n) always lies between c1.g(n) and
c2.g(n) inclusive.
Ɵ: Big theta- Example
Q1. prove that f(n)=2n+3 is Ɵ(n)
Exercise #2
1. prove that f(n)=5+3n+1 is:
b) O() b) 𝛀 () c) Ɵ()
because it will give us an upper limit of the execution time i.e. the
the lower order terms are relatively insignificant for large input.
E.g.
let f(n)=2+3n+5
f(n)=O+3n+5)=> O()