Algorithm and Flowchart Notes
Algorithm and Flowchart Notes
Design of solution
The solution to the problem can be designed by using tools such as algorithm and
flowchart.
Algorithm Development:
The word algorithm originates from the word 'algorism' which means the process
of doing arithmetic with numerals. Mathematician Al-Khwarizmi developed methods for
solving problems which used step-by-step instructions.
Characteristics of an algorithm:
Given three numbers a, b, c this algorithm finds the greatest and store the result in the
variable large.
Step 1: Start
Step 2: [Read 3 numbers]
Input a, b, c
Step 3: [Assign a to large]
large=a
Step 4: [Compare large and b]
if(large<b)
large=b
endif
Step 5: [Compare large and c]
if(large<c)
large=c
endif
Step 6: [Print large]
Output large
Step 7: Stop
Given a number n, this algorithm finds the factorial of n and store the result in the
variable fact. The variable i is the for loop counter that varies from 1 to n.
Step 1: Start
Step 2: [Read the number]
Input n
Step 3: [Initialize factorial to 1]
Fact=l
Step 4: [Compute the factorial]
Repeat for i = 1 to n
Fact=Fact * i
[End of step 4 for loop]
Step 5: [Print factorial of given number]
Output Fact
Step 6: Stop
Step 1: Start
Step 2: [Read the number]
Input n
Step 3: [Initialize value of limit]
limit=sqrt(n)
Step 4: [check for prime]
Repeat for i = 2 to limit
if( n%i=0) then
output “number is prime”
else
output “number is not prime
[End of step 4 for loop]
Step 5: [Print factorial of given number]
Output Fact
Step 6: Stop
Flowcharts:
ii. System flowchart: It gives an overall view of system environment and flow of
operations for an algorithm.
Flowchart Symbols
prime or not
Pseudo code:
It is a narrative description of the flow and logic of the program, written in plain language
that expresses each step of an algorithm.
Words commonly used in pseudo code are set, reset, increment, compute, calculate, add, sum,
multiply, ... print, display, input, output, edit, test , etc.
Purpose of pseudocode:
Advantages :
1. It allows the designer to focus on main logic without being distracted by programming
languages syntax.
2. Since it is language independent, it can be translated to any computer language code.
3. It allows designer to express logic in plain natural language.
4. It is easier to write actual code using pseudocode.
5. Unlike algorithms, pseudocodes are concise so pseudocodes are more readable and easier
to modify.
Disadvantages :
1. There are no accepted standards for writing pseudocodes and designer use their own style while
writing pseudocodes.
2. Pseudocode cannot be compiled and executed so its correctness cannot be verified by usi ng
computers.