Algorithm and Flowchart
PROBLEM SOLVING TECHNIQUES
Definition: The task of expressing the solution of complex problems in terms of simple
operations understood by the computer.
Design of solution
The solution to the problem can be designed by using tools such as algorithm and
flowchart.
Algorithm Development:
An algorithm is a step-by-step finite sequence of instructions, to solve a well-defined
problem.
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:
i. Input: The algorithm must accept one or more data to be processed.
ii. Definite: Each operational step or operation must be definite. i.e., each and
every instruction must clearly specify that what should be done.
iii. Effective: Each operational step can at least carry out by a person in a
minimum number of times.
iv. Terminate: After some minimum number of operations algorithm must come
to an end.
v. Output: It must produce one or more computed result.
An algorithm to find greatest(largest) of 3 numbers.
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
SBC Karkala Page 1
Algorithm and Flowchart
An algorithm to find factorial of a number.
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
An algorithm to check for prime number
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:
The diagrammatic representation of an algorithm is called flowchart.
There are 2 types of flowcharts.
i. Program flowchart: It specifies the flow of operations of an algorithm, pictorially.
ii. System flowchart: It gives an overall view of system environment and flow of
operations for an algorithm.
Importance (advantage) of flowchart:
1. Communication: Flowcharts are better way of communication of the logic of a
program.
2. Effective analysis: With the help of flowcharts the problem can be analyzed in
more effective way.
SBC Karkala Page 2
Algorithm and Flowchart
3. Efficient coding: The flowchart act as blue print during the system analysis and
program development phase.
4. Proper debugging: The flowchart helps in debugging process.
5. Efficient program maintenance: The maintenance of a program becomes easy with
the help of flowchart.
Flowchart Symbols
Flowchart to find the area and circumference of a circle
SBC Karkala Page 3
Algorithm and Flowchart
Flowchart to find the area of triangle Write a Flowchart to check whether a number is
prime or not
Flowchart to find the greater of two
numbers
SBC Karkala Page 4
Problem Solving Methodology
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:
Pseudocode is sometimes used as a detailed step in the process of developing a program. It
allows designers or lead programmers to express the design in great detail and provides
programmers a detailed template for the next step of writing code in a specific programming
language.
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.
SBC Karkala Page 5