Vous êtes sur la page 1sur 10

Introduction:

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?

Suma M G, Asst Prof, MCA of Dept

RNSIT

AlgorithmandFlowcharts

Similarly to provide the output of a program we may have to answer certain question
such as:

What are the outputs generated by the program?


What is the format of the outputs?
What is the output device?
How the outputs should be displayed?

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.

Suma M G, Asst Prof, MCA of Dept

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.

Suma M G, Asst Prof, MCA of Dept

RNSIT

AlgorithmandFlowcharts

Disadvantages:

1. It is time consuming because uses of a number of symbol which are to be properly


represented.
2. The representation of complex logic is very difficult
3. Alterations and modifications is very difficult to redrawing the flowchart.
4. Reproduction of flowchart becomes problems since symbols cannot be typed.
Symbols used in flowcharts:
Sl No.

Symbols

Purpose

1.

Terminal: The beginning and end of the program

2.

Input/Output: This is used to accept the variable for


processing and display the processed results.

3.

Processing: This is used to process the data such as


calculations, manipulations

4.

Preparation: is used for repeating steps several numbers of


times until the given condition is satisfied.

5.

Decision: is used for comparison, decision making and


branching.

6.

Predefined Process: is used to define a module or


sub-program.

7.

Connector: It is used to connect the flowchart or data flow if


it exceeds one page.

8.

Flow Direction: It indicates the flow of data from one


geometrical signal to another.

9.

System: is used to specified the file which is access from the


directory

Suma M G, Asst Prof, MCA of Dept

RNSIT

AlgorithmandFlowcharts

Example-1: Algorithm and flowchart to find biggest of 3 numbers


Step 1: Start
Step 2: Input A, B and C
Step 3: if (A>B)&&(A>C)
Output A is biggest
else if (B>C)
Output B is biggest
else
Output C is biggest
endif
Step 4: Stop

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

Suma M G, Asst Prof, MCA of Dept

RNSIT

AlgorithmandFlowcharts

Example-2: Algorithm and Flowchart to swap the two numbers.

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

Suma M G, Asst Prof, MCA of Dept

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 "Not Possible"

Write area

STOP

Suma M G, Asst Prof, MCA of Dept

RNSIT

AlgorithmandFlowcharts

Example-5: Algorithm and Flowchart to find Factorial of a number.


Step 1: Start
Step 2: Input n
Step 3: for i1 to n step of 1 do
fact fact * i;
end for
Step 4: Output fact
Step 5: Stop

START

Read n

for i = 1 to n

fact = fact

* i

Write fact

STOP

Example-6: Algorithm and Flowchart to solve quadratic equation.


Step 1: Start
Step 2: Input a, b, c
Step 3: if(a==0)then
Output Equation is linear and has only one root
else
desc=b*b-4*a*c;
if(desc==0) then
r1 -b/(2*a);
r2 -b/(2*a);
Output The roots are real and equal
Output r1,r2
else if(desc>0) then
r1 (-b+sqrt(desc))/(2*a)
r2 (-b-sqrt(desc))/(2*a)
Output The roots are real and distinct"
Output r1,r2

Suma M G, Asst Prof, MCA of Dept

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
?

Write "Root are


equal"

False

True
x1 = -b/2*a
x2 = -b/2*a

Write "Root are


distinct"

Write x1, x2
x1 = -b+sqrt(d)/(2*a)
x2 = -b-sqrt(d)/(2*a)

Write "Root are


imaginary"
x1 = b/(2*a)
x2 = sqrt(-d)/(2*a)

Write x1,x2
Write x1,x2

STOP

Suma M G, Asst Prof, MCA of Dept

10

RNSIT

Vous aimerez peut-être aussi