1.2-Algorithm & Flow Chart
1.2-Algorithm & Flow Chart
Dr. D. NATARAJASIVAN
Lecturer
TNPT
D.NATARAJASIVAN/ TNP
T
Topics
▪ Algorithm-Definition
▪ Properties and Classification of
Algorithm
▪ Flow Chart-Symbols
▪ Importance and Advantages of Flow
Chart
▪ Algorithm and Flow Chart for problems
D.NATARAJASIVAN/ TNP
T
Algorithm Definition
▪ An algorithm is a set of
step-by-step instructions
written in simple English
to perform a specific
task.
D.NATARAJASIVAN/ TNP
T
Properties of Algorithm
▪ Easy to understand
▪ Input and Output are clearly
defined
▪ Calculation steps are clearly given
▪ Does not contain any program code
▪ Written in finite steps
D.NATARAJASIVAN/ TNP
T
Classification of Algorithm
Contd…
▪ For Loop –
▪ Sub process –
▪ Flow Direction –
▪ Connector –
D.NATARAJASIVAN/ TNP
Importance and T
of Circle
▪ Algorithm
Step 1) Start.
Step 2) Get radius r value.
Step 3) Calculate area as (22/7) * r * r.
Step 4) Calculate circumference as
2*(22/7)*r.
Step 5) Display area and circumference.
Step 6) Stop.
Flow Chart
Start
Get r value
Area = (22/7) * r *
r
Circum =
2*(22/7)* r
Display
area and
Circum
Stop
D.NATARAJASIVAN/ TNP
numbers
▪ Algorithm
Step 1) Start
Step 2) Get value for N
Step 3) Initialize res = 1
Step 4) For i = 1 to N do the following
i) Calculate res = res * i
Step 5) Next i
Step 6) Display res
Step 7) Stop
Flow Chart
Start
A
Get N
Display
value
res
res = 1
Stop
for i = 1 to N
res = res * i
Next
i A
D.NATARAJASIVAN/ TNP
T
Largest of 3 Numbers
▪ Algorithm
Step 1) Start
Step 2) Get values for a,b,c
Step 3) Check if a>b and a>c then
i) Display ‘a’ is largest
Step 4) Else check if b>c then
i) Display ‘b’ is largest
Step 5) Else
i) Display ‘c’ is largest
Step 6) Stop
D.NATARAJASIVAN/ TNPT
Flow Chart
Start
Get a,b,c
If
a>b False
&
Truea>c
Display If False
‘a’ is b>c
True
Display Display
largest
‘b’ is ‘c’ is
largest largest
Stop
D.NATARAJASIVAN/ TNP
T
▪ Algorithm
Step 1) Start
Step 2) Input n
Step 3) Calculate res = n mod 2
Step 4) If res equal to 0 then
i) Display “Even”
Step 5) else
i) Display “Odd”
Step 6) Stop
D.NATARAJASIVAN/ TNPT
Flow Chart
Start
Input n
res = n mod 2
If res False
== 0
True
Display Display
“Even” “Odd”
Start
Factorial of a given D.NATARAJASIVAN/ TNP
T
number
▪ Algorithm
Step 1) Start
Step 2) Input n
Step 3) Initialize fact = 1
Step 4) While n >= 1 do the following
i) calculate fact = fact * n
ii) calculate n = n – 1
Step 5) Output fact
Step 6) Stop
D.NATARAJASIVAN/ TNPT
Flow Chart Start
Input n
fact =1
Whil
e
n False
>=
True
fact =1 fact
*n
n=n-1
Output
fact
Stop