Lecture - 1 (A)
Lecture - 1 (A)
FALL 2024
Lecture No:01(A)
Introduction of Algorithms
What is an algorithm
Properties of Algorithms
Algorithm’s Notations
2
At the End of Lecture
3
What is an algorithm
4
Properties of algorithm
Complete
Finite
At least one Output
0,1 or more inputs
Correct
Clarity
5
An Algorithm (Example)
Algorithm Name
– Should be in capital form
– Meaningful
Parameters
– Should be enclosed in parenthesis ( )
– Variable name comprises on more than one characters
– Scripting or looping variable are of single character
Introductory Comment
– Description and purpose of an algorithm
Steps
– Finite steps
7
Algorithms Notations (Cont !!!)
Comments
– Each step start with a comment
– Enclose in [ ]
– Define the purpose of step
Input Statements
– Read
– Scanf (if using C/C++)
Output statement
– Write
– Printf (if using C/C++)
8
Algorithms Notations (Cont !!!)
Selection statement
– If –Then –End If
– If – then ---Else --- End If
– Nested If
– Example
If ( a>b ) then
write ( a+”Is Large”)
Else
write ( b+”Is Large”)
End if
9
Algorithms Notations (Cont !!!)
10
Algorithms Notations (Cont !!!)
Finish
– Exit (Used in main algorithm)
– Return (Used in sub algorithm)
11
Example-1.
12
Algorithm Example-1.
13
Algorithm Example-1 (Cont !!!)
14
Algorithm Example-1 (Cont !!!)
15
Pseudo code Example-1 (Cont !!!)
16
Example-2.
17
Algorithm Example-2.
19
Algorithm Example-2 (Cont !!!)
20
Pseudo code Example-2(Cont !!!)
21
Example-3.
22
Algorithm Example-3.
24
Pseudo code Example-3(Cont !!!)
Facorial(No, Res)
{
Res= Fact (No)
Printf(“%d”, Res)
Fact(NewNo)
}
{
for(i=1;i<=N;i++)
F=F* I
Return(f)
}
25
Summary
26