CSC4321 - Introduction - 1
CSC4321 - Introduction - 1
CSC4321/4421
Lecture #1
Synopsis
algorithms.
Big ‘O’ notation
Order-of-Magnitude Analysis and Big O
Notation
Order-of-Magnitude Analysis and Big O
Notation
Order of increasing complexity
Example of algorithm
(only for cout operation):
Example of algorithm
(only for cout operation):
Example of algorithm
(only for cout operation):
Example of algorithm
(only for cout operation):
Example of algorithm
(only for cout operation):
Example of algorithm
(only for cout operation):
Example of algorithm
(only for cout operation):
Determine the Complexity time of Algorithm
Theoretically – by calculation
Practically
Implement the algorithms in any programming language and run the programs
Theoretically
Count the number of steps and then find the class of complexity.
Find the complexity time for each steps and then count the total.
Example 1: Determine the number of steps
int counter = 1;
int i = 0;
counter++;
how ?
Example 1: Solution
Number Statements
1 int counter = 1;
2 int i = 0;
3 i=1
4 i <= n
5 i++
6 cout << “Analysis of Algorithm" << counter << "\n";
7 counter++;
Example 1: Solution
Statement 3, 4 & 5 are the loop control and can be assumed as one statement.
Number Statements
1 int counter = 1;
2 int i = 0;
3,4,5 i = 1; i <= n; i++
6 cout << “Analysis of Algorithm" << counter << "\n";
7 counter++;
Example 1: Solution
example:- if n = 5, i = 1
Example 1: Solution
example:- if n = 5, i = 3
Example 1: Solution
example:- if n = 1, i = 1
Example 1: Solution
int counter = 1; 1
∑ f(i) = 1
i=1
int i = 0; 1
∑ f(i) = 1
i=1
i = 1; i= n; i++ n
∑ f(i) = n
i=1
cout << “Analysis of Algorithm" n 1
∑ f(i) ∑ f(i) = n.1 = n
<< counter << "\n"; i=1 i=1
counter++ n 1
∑ f(i) ∑ f(i) = n.1 = n
i=1 i=1
Example 1: Solution
Example 2:
Algorithm
void example2( )
}
Example 2: Solution
void example2( ) 0
{ 0
} 0
Total 2(n-1)
void sample1 ( )
void sample2 ( )
}
Class work
void sample3 ( )