Computer Application [1st Semester/2nd Semester]
CHAPTER – 5
[Problem Solving Methodology]
Algorithm
Algorithm is defined as the step by step solution of problem in user’s language. It is considered as an effective
procedure for solving a problem in finite number of steps. The characteristics of Algorithm are
Precise
Unambiguous
Finite termination
Unique solution
Once algorithm is written, it can be coded into a program using any programming language.
Algorithm uses 3 different constructs
Sequence
Branching or Decision making
Repetition
Sequence says that instructions are to be executed in what order or sequence. Branching involves testing of
condition and based on the outcome of the condition testing different instructions are executed. Repetition
means one or more instructions shall be repeated for a number of times. This is otherwise called as loop.
Example:
1. Algorithm to find out sum of two numbers to be taken as input.
Step-1: Read the 1st number a
Step-2: Read the 2nd number b
Step-3: Sum=a+b
Step-4: Print Sum
(This is an example where only sequence is exhibited)
2. Algorithm to find out larger between numbers to be taken as input.
Step-1: Read the 1st number x
Step-2: Read the 2nd number y
Step-3: If x > y
Then Print x
Else
Then Print y
(This is an example where Branching is exhibited)
3. Algorithm to find out sum of first 10 natural numbers.
Step-1: i=1, Sum=0
Step-2: Repeat step 3 and 4 while i<=10
Step-3: Sum= Sum+i
Step-4: i=i+1
Step-5: Print Sum
(This is an example where Repetition is exhibited)
1
By Mr.S.Rupak Kumar (Lect.)
Computer Application [1st Semester/2nd Semester]
Flowchart
Flowchart is a graphical or symbolic representation of the process of solution to a problem
or algorithm. It helps to visualize the complex logic of the solution of the problem in a
simplified manner through diagrammatic representation. Each step of the algorithm is
presented using a symbol and a short description. The different symbols used for the
flowchart are
Start or Stop
Input or Output
Process
Decision Making
Arrow for sequence
Connector
Example:
1. Flowchart to find out sum of two numbers to be taken as input
start
Read x, y
Sum=x+y
Print sum
Stop
2
By Mr.S.Rupak Kumar (Lect.)
Computer Application [1st Semester/2nd Semester]
2. Flowchart to find out larger between two numbers to be taken as input
start
Read x, y
YES
x>y ? Print x
No
YES
X<y ? Print y
Print Both Equal
Stop
3. Flowchart to find out sum of first 10 natural numbers
start
i=1 , Sum=0
Sum= Sum +i
i=i+1
i<=10
?
Print sum
Stop
3
By Mr.S.Rupak Kumar (Lect.)
Computer Application [1st Semester/2nd Semester]
Pseuodocode
It is a concise description algorithm in English language that uses programming language
constructs. It contains outlines of the program that can be easily converted to program. It
focuses on the logic of the algorithm without giving stress on the syntax of programming
language. This is meant for understanding the logic of the program easily. Flowchart can be
considered as an alternative to pseudocode. Several constructs/key words of programming
language can be used in the algorithm to write the pseudocode. Some of them are:
a) If ... Endif
b) Do while ... end do
c) While ... end while
d) Repeat ... until
e) For ... end for
f) Case ... end case
g) Call
h) Return
4
By Mr.S.Rupak Kumar (Lect.)