Académique Documents
Professionnel Documents
Culture Documents
AlgorithmandFlowcharts
When we write a computer programs, we write it to solve a set of problems not just one.
Problem solving can be defined as The task of expressing the solution of complex problems
in terms of simple operations understood by the computer.
In order to solve a problem using a computer we will have to pass through certain stages. The
stages are:
1. Problem definition
2. Problem analysis
3. Design of a solution using design tools such as Flowcharts and Algorithms
4. Coding (Programming the computer)
5. Testing and Debugging(Checking and correcting)
6. The documentation of the program
7. Program maintenance or enhancement
1. Problem Definition:
The basic concept, which should be clearly understood, is that Success can be achieved
in problem solving only when we know what we want to do, that means the problem
should be clearly understood first by the user. We cannot make any progress if we do not
understand the problem. In this step of problem solving we analyze what must be done rather
than how to do it.
Problem definition requires us to develop exact specification of the problem. The
problem definition should be in the users language such as English of some other natural
language; I may include charts, tables and equations of different kinds.
2. Problem Analysis:
In this problem analysis, we try to understand the requirements of the problem to be
solved. This process is the first step towards the solution. Explicit requirements about input
output, time constraints, processing requirements, accuracy, memory limitations, error
handling and interfaces are understood at this stage. The end result of this analysis is the
selection of a method, which is to be used on the computer.
To completely and properly specify the input to a program we may have to answer
certain questions such as:
What are the values, which should be provided to the program?
What type of input is to be provided?
What is the format of certain types of data?
What is the accuracy of the input data?
What is the input device?
What is the range of values allowed for a particular input?
RNSIT
AlgorithmandFlowcharts
Similarly to provide the output of a program we may have to answer certain question
such as:
3. Design of a Solution:
Once the process of problem definition and problem analysis is complete, it is
necessary for us to define the solution to the problem. The solution should include a sequence
of well-defined steps that will input and manipulate the data and produce the desired output.
The process of good designing can be done efficiently with the choice of certain design tools
such as algorithm and flowchart.
Complex problems can be effectively solved using the computer when they are
broken down into sub-problems. Sub-problems are easier to solve than the complete problem.
This approach sometimes called as divide and conquers or top-down design, can be
applied to the construction of the problem solution and to the writing of the computer
program.
Advantages of top-down design are:
The problem is easily understood and can be logically organized into parts called
modules. Thus, there is a structure to the solution of the problem.
Modifications or changes can be easily made to the modules.
Testing the solution can be easily performed.
4. Coding:
The process of converting the representation of a solution into a set of instructions in
a programming language is referred to as coding.
OR
The process of writing program instructions for an analyzed problem in a
programming language.
Algorithms and flowcharts can be written in ordinary language or using formal
procedures because the emphasis is more on the representation of the solution and not on
syntax. During coding the programmer takes each step converts it into a proper
representation using proper syntax and logic. The process is said to be successful or complete
when the compiled version does not generate any error.
5. Debugging:
The process of detecting and correcting errors in a program is referred to as
Debugging.
OR
The process of finding and correcting program errors (bugs).
Suma M G, Asst Prof, MCA of Dept
RNSIT
AlgorithmandFlowcharts
Very few programs run correctly for the first time. Thus debugging is a very important and
time-consuming phase of software development. The process of debugging ensures that the
program does what the programmer intends to do. This stage is also referred to as
verification and testing is referred to as validation.
The process of debugging requires us to follow the following sequence of steps.
The program is first compiled. During the process of compilation the compiler detects
certain types of errors called as syntax errors [occurs due to the wrong use of
syntax].
All the detected errors are corrected and the program is recompiled. The process is
repeated till no errors are displayed.
The program is then executed. During the execution of a program certain errors called
as semmantic errors [occurs due to the wrong use of logic]are detected.
Once all the errors are corrected the program is recompiled again and executed.
6. Program Documentation:
The written text and comments that makes a program easier for others to understand,
use and modify.
The process of program documentation helps at various stages in the development of
a program. It is always said that a properly documented program can be easily reused again
when needed, whereas an undocumented program requires so much effort that it is better to
write a new program.
Comments are a basic part of program documentation. However comments should be
used to explain the purpose of a program instruction and not be used to repeat the meaning of
the instruction.
7. Program Maintenance:
The process of updating or providing new versions of a program so that the program
meets the present day requirements of the user.
Program Maintenance may be required for the following reasons.
The needs of the user have changed over a period of time and the program has to be
modified to meet the present day needs.
The existing program is not functioning to the satisfaction of the user, thus the
program has to be modified to provide the additional information.
New errors or bugs, which were not detected during development and testing, were
detected during the usage of the program.
The user has seen the program is functioning properly on the new system.
RNSIT
Algorithm:
AlgorithmandFlowcharts
The word algorithm is derived from the name of a 9th century Arab mathematicians,
Al-Khowarizmi, who developed methods for solving problems which used specific step-by-step
instructions.
An algorithm is step-by-step procedure to solve a given problems.
OR
A sequence of unambiguous instructions for solving a problem in a finite number of
operations.
Characteristics of an algorithm are:
1.
2.
3.
4.
5.
It should be simple
Steps of an algorithm should not be ambiguity
Range of the input must be specified
It should have finite number of steps
It should produce atleast one output.
Advantages:
1. It is a step-by-step representation of solution to a given problem, which is easy to
understand.
2. It is easy to develop an algorithm and then convert it into a flowchart and then into a
computer program
3. It is independent of programming language
4. It is easy to debug as every step has got its own logical sequence.
Disadvantages:
1. To represent a complex logic is a very difficult
2. It is time consuming.
FlowtCharts:
A flowchart is a pictorial or graphical representation that uses predefined symbols of
a solution to any problem.
Advantages:
1. Easy to understand and convert into a program
2. It is independent of programming language
3. Easy to debug as every step has got its own logical sequence.
RNSIT
AlgorithmandFlowcharts
Disadvantages:
Symbols
Purpose
1.
2.
3.
4.
5.
6.
7.
8.
9.
RNSIT
AlgorithmandFlowcharts
START
Read A,B,C
True
Write "A is
biggest"
False
is (A>B
&& A>C)?
True
Write "B is
biggest"
is
(B>C)?
False
Write "C is
biggest"
STOP
RNSIT
AlgorithmandFlowcharts
Step
Step
Step
Step
Step
Step
Step
1:
2:
3:
4:
5:
6:
4:
START
Start
Input A,B
temp A
A B
B temp
Output A, B
Stop
Read A, B
temp = A
A = B
B = temp
Write A, B
STOP
Example-3: Algorithm and Flowchart to check whether given numbers is even or odd.
Step 1: Start
Step 2: Read n
Step 3: if (n%2 == 0) then
Output n is even
else
Output n is odd
endif
Step 4: Stop
START
Read n
True
is (n%2
== 0) ?
Write "number
is even"
False
Write "number
is odd"
STOP
RNSIT
AlgorithmandFlowcharts
Example-4: Algorithm and Flowchart to find the area of triangle for given 3 sides.
Step 1: Start
Step 2: Input a, b, c
Step 3: if (a+b<=c || b+c<=a || c+a<=b) then
Output Not Possible
Goto Step 5
else
s (a+b+c)/2
area sqrt( s*(s-a)*(s-b)*(s-c))
endif
Step 4: Output area
Step 5: Stop
START
Read a,b,c
True
is(a+b<=c
|| b+c<=a ||
c+a<=b ?
False
s = (a+b+c)/2
area = sqrt(s*(s-a)*(s-b)*(s-c))
Write area
STOP
RNSIT
AlgorithmandFlowcharts
START
Read n
for i = 1 to n
fact = fact
* i
Write fact
STOP
RNSIT
AlgorithmandFlowcharts
else
real -b/(2*a)
img sqrt(-desc)/(2*a)
Output The roots are imaginary
Output real, img
endif
endif
endif
Step 5: Stop
START
Read a,b,c
True
False
is a=0
?
d=b*b - 4*a*c
Write "Root are
linear"
is d==0
?
False
True
is d>0
?
False
True
x1 = -b/2*a
x2 = -b/2*a
Write x1, x2
x1 = -b+sqrt(d)/(2*a)
x2 = -b-sqrt(d)/(2*a)
Write x1,x2
Write x1,x2
STOP
10
RNSIT