Algorithms and Flowcharts
The software developer makes use of tools like algorithms and flowcharts to
develop the design of the program.
Algorithm
An algorithm represents the logic of the processing to be performed. It is a
sequence of instructions which are designed in such a way that if they are
executed in the specified sequence, the desired goal is achieved. It is imperative
that the result be obtained after execution of a finite number of steps.
The word “algorithm” relates to the name of the mathematician Al-khowarizmi,
which means a procedure or a technique. Software Engineer commonly uses an
algorithm for planning and solving the problems.
An algorithm is a sequence of steps to solve a particular problem or algorithm
is an ordered set of unambiguous steps that produces a result and terminates in a
finite time
In an algorithm,
- Each and every instruction has to be precise and clear.
- The instruction has to be executed in a finite time.
- When the algorithm terminates the desired result should be achieved.
Advantages of Algorithms
• It is a step-wise representation of a solution to a given problem, which
makes it easy to understand.
• An algorithm uses a definite procedure.
• It is not dependent on any programming language, so it is easy to
understand for anyone even without programming knowledge.
• Every step in an algorithm has its own logical sequence so it is easy to
debug.
Flowchart
A flowchart is a pictorial representation of the algorithm. It represents the steps
involved in the procedure and shows the logical sequence of processing using
boxes of different shapes. The instruction to be executed is mentioned in the
boxes.
These boxes are connected together by solid lines with arrows, which indicate
the flow of operation. The first step in the design of a program is the algorithm.
The algorithm is then represented in the form of a flowchart and the flowchart is
then expressed in the computer language to actually prepare the computer
program.
The first design of flowchart goes back to 1945 which was designed by John
Von Neumann. Unlike an algorithm, Flowchart uses different symbols to design
a solution to a problem. It is another commonly used programming tool. By
looking at a Flowchart, one can understand the operations and sequence of
operations performed in a system. Flowchart is often considered as a blueprint
of a design used for solving a specific problem.
Advantages of flowchart:
• Flowchart is an excellent way of communicating the logic of a program.
• Easy and efficient to analyse problem using flowchart.
• During program development cycle, the flowchart plays the role of a
blueprint, which makes program development process easier.
• After successful development of a program, it needs continuous timely
maintenance during the course of its operation. The flowchart makes
program or system maintenance easier.
• It is easy to convert the flowchart into any programming language code.
Flowchart is diagrammatic /Graphical representation of sequence of steps to
solve a problem. To draw a flowchart following standard symbols are use:
Types of logic used in the flowchart:
Both algorithm and flowchart include following three types of logics or control
structures.
➢ Sequential Execution: In this logic the instructions are executed one
after the other sequentially.
In the sequence structure, statements are placed one after the other and
the execution takes place starting from up to down.
➢ Transfer of control: This is a logic which is used when the option to be
chosen depends upon the result of the decision. The control is transferred
to a particular path if the result of the decision branches to that path.
It is also called branching and selection. In branch control, there is a
condition and according to a condition, a decision of either TRUE or
FALSE is achieved. In the case of TRUE, one of the two branches is
explored; but in the case of FALSE condition, the other alternative is
taken. Generally, the ‘IF-THEN’ is used to represent branch control.
➢ Looping: In looping or repetitive logic, an instruction or a number of
instructions are executed more than once. The instructions are executed
till the decision criteria is true. The decision criteria can be placed before
the loop or after the loop depending upon the statements which are to be
executed in the loop.
The Loop or Repetition allows a statement(s) to be executed repeatedly
based on certain loop condition e.g. WHILE, FOR loops.
Let us see some examples of writing algorithms and flowcharts.
1. Write an algorithm and develop a flowchart to convert the
temperature input in Celsius scale to Fahrenheit scale.
Solution :
First write a detailed stepwise algorithm to do the conversion
Algorithm:
Step 1: Start.
Step 2: Input temperature in Celsius (C).
Step 3: Convert to Fahrenheit (F) using the formula F = 9/5 * C + 32.
Step 4: Print the temperature in Fahrenheit (F).
Step 5: Stop.
Next on the basis of this step wise algorithm develop the flowchart using the
appropriate flowchart symbols as follows:
Flowchart:
Start
Input Temp. in C
Calculate F
F= 9/5 C + 32
Print Temp. in F
Stop
2. Write an algorithm and flowchart to read two numbers A and B and
compare
them. If A is greater than B print, A is greater than B else print B is greater
than A.
Algorithm :
Step 1: Start.
Step 2: Input values of A and B.
Step 3: Compare values of A and B (Is A >B?).
Step 4: If yes then print “A is greater than B”.
Step 5: If no, the print “B is greater than A”.
Now draw the flowchart for the above.
3. Algorithm & Flowchart to find the sum of two numbers
Algorithm
Step-1 Start
Step-2 Input first numbers say A
Step-3 Input second number say B
Step-4 SUM = A + B
Step-5 Display SUM
Step-6 Stop
Flowchart:
4. Algorithm & Flowchart to find Area and Perimeter of Rectangle
L : Length of Rectangle
B : Breadth of Rectangle
AREA : Area of Rectangle
PERIMETER : Perimeter of Rectangle
Algorithm
Step-1 Start
Step-2 Input Side Length & Breadth say L, B
Step-3 Area = L x B
Step-4 PERIMETER = 2 x ( L + B)
Step-5 Display AREA, PERIMETER
Step-6 Stop