You are on page 1of 10

An introduction to Flowcharts

What is a Flowchart?
Flowchart is a graphical representation of an algorithm. Programmers often use it as a program-
planning tool to solve a problem. It makes use of symbols which are connected among them to
indicate the flow of information and processing.
The process of drawing a flowchart for an algorithm is known as “flowcharting”.

Flowchart is a diagrammatic representation of an algorithm. Flowcharts are very helpful in


writing program and explaining program to others.

Advantages of flowchart:
• Flowchart is an excellent way of communicating the logic of a program.

• Easy and efficient to analyze 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

Symbols Used In Flowchart


Different symbols are used for different states in flowchart, For example: Input/Output and
decision making has different symbols. The table below describes all the symbols that are used in
making flowchart

Symbol Purpose Description

Flow line Used to indicate the flow of logic by connecting symbols.

Terminal(Stop/Start
) Used to represent start and end of flowchart.
Symbol Purpose Description

Input/Output Used for input and output operation.

Processing Used for airthmetic operations and data-manipulations.

Used to represent the operation in which there are two alternatives,


Desicion true and false.

On-page Connector Used to join different flowline

Off-page Connector Used to connect flowchart portion on different page.

Examples of flowcharts in programming

Example 1: Draw a flowchart to add two numbers entered by user.


Example 2: Draw flowchart to find the largest among three different numbers entered by

user.

Example3: Draw a flowchart to find all the roots of a quadratic equation ax2+bx+c=0

Example 4: Draw a flowchart to find the Fibonacci series till term≤1000.


Though, flowchart are useful in efficient coding, debugging and analysis of a program, drawing
flowchart in very complicated in case of complex programs and often ignored.

Introduction to Algorithms

Algorithm:
Algorithm is a step by step description of how to arrive at a solution of any given problem.

Or

You can say that, an algorithm of any program is the step by step solution description of the
given program or problem.

Characteristic of an Algorithm
Algorithm has the following characteristics

• Input: An algorithm may or may not require input

• Output: Each algorithm is expected to produce at least one result

• Definiteness: Each instruction must be clear and unambiguous.


• Finiteness: If the instructions of an algorithm are executed, the algorithm should terminate
after finite number of steps

Advantage of an Algorithm
 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.

Logic to Design Algorithm and Flow Chart


The algorithm and flowchart include following three types of control structures.

1. Sequence Logic: In the sequence structure, statements are placed one after the other and the
execution takes place starting from up to down.

2. Branching (Selection/Decision) Logic: In branch control, there is a condition and according


to a condition, a decision of ither 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.

3. Iteration (Repetition) Logic: The Loop or Repetition allows a statement(s) to be executed


repeatedly based on certain loop condition e.g. WHILE, FOR loops.

HOW TO WRITE ALGORITHMS


Step 1: Define your algorithms input: Many algorithms take in data to be processed, e.g. to
calculate the area of rectangle input may be the rectangle height and rectangle width.

Step 2: Define the variables: Algorithm's variables allow you to use it for more than one place.
We can define two variables for rectangle height and rectangle width as HEIGHT and WIDTH
(or H & W). We should use meaningful variable name e.g. instead of using H & W use HEIGHT
and WIDTH as variable name.

Step 3: Outline the algorithm's operations: Use input variable for computation purpose, e.g. to
find area of rectangle multiply the HEIGHT and WIDTH variable and store the value in new
variable (say) AREA. An algorithm's operations can take the form of multiple steps and even
branch, depending on the value of the input variables.
Step 4: Output the results of your algorithm's operations: In case of area of rectangle output
will be the value stored in variable AREA. if the input variables described a rectangle with a
HEIGHT of 2 and a WIDTH of 3, the algorithm would output the value of 6.

Algorithms Design: Top-down and Bottom-up


Approach in C Programming
Today we are going to have a comparative study of the two approaches being used in field of
structured and object oriented programming. We shall start with a brief understanding of the both
followed by comparison and conclusion.

When talking in terms of computer science and programming, the algorithms we use to solve
complex problems in a systematic and controlled way are designed on the basis of two
approaches that is Top-down and Bottom-up approach. The ideology behind top-down approach
is, a bigger problem is divided into some smaller sub-problems called modules, these modules
are then solved individually and then integrated together to get the complete solution to the
problem. In bottom-up approach on the other hand, the process starts with elementary modules
and then combining together to get the desired result. Let us now quickly see in brief what these
two approaches has to offer, how they differ from each other and what are the similarities.

Top-Down Approach

The basic idea in top-down approach is to break a complex algorithm or a problem into smaller
segments called modules, this process is also called as modularization. The modules are further
decomposed until there is no space left for breaking the modules without hampering the
originality. The uniqueness of the problem must be retained and preserved. The decomposition
of the modules is restricted after achieving a certain level of modularity. The top-down way of
solving a program is step-by-step process of breaking down the problem into chunks for
organising and solving the sole problem. The C- programming language uses the top-down
approach of solving a problem in which the flow of control is in the downward direction.

Bottom-Up Approach

As the name suggests, this method of solving a problem works exactly opposite of how the top-
down approach works. In this approach we start working from the most basic level of problem
solving and moving up in conjugation of several parts of the solution to achieve required results.
The most fundamental units, modules and sub-modules are designed and solved individually,
these units are then integrated together to get a more concrete base to problem solving.

This bottom-up approach works in different phases or layers. Each module designed is tested at
fundamental level that means unit testing is done before the integration of the individual modules
to get solution. Unit testing is accomplished using low-level functions that are another topic we
will talk about later.

Let us now see a comparative study of both the strategies and try to understand what are
common and odds among them.

Difference between Top-down and Bottom-up Approach

Top-Down Approach Bottom-Up Approach

Divides a problem into smaller units and Starts from solving small modules and
then solve it. adding them up together.

This approach contains redundant


information. Redundancy can easily be eliminated.

A well-established communication is not


required. Communication among steps is mandatory.

The individual modules are thoroughly Works on the concept of data-hiding and
analyzed. encapsulation.

Structured programming languages such as OOP languages like C++ and Java, etc. uses
C uses top-down approach. bottom-up mechanism.

Relation among modules is not always The modules must be related for better
required. communication and work flow.
Primarily used in code implementation, test
case generation, debugging and module
documentation. Finds use primarily in testing.

Conclusion:

After having a sound discussion on this we all should now have got a clear understanding of the
two approaches. The top-down approach is the conventional approach in which decomposition of
higher level system into lower level system takes place respectively. Talking about the bottom-
up mechanism for algorithm designing, starting from designing lower abstraction modules and
then integrating them to higher level provides better efficiency.

We have seen the modules in top-down approach aren’t connected in a manner so that they can
communicate well, so giving rise to redundancies, whereas in the later case the redundancies are
omitted to large extent. The feature of information hiding and reusability provided by bottom-up
approach makes this mechanism even more popular.

Comment below if you have doubts regarding difference between Top-down and Bottom-up
approach.

Pseudo code:
Pseudocode is one of the tools that can be used to write a preliminary plan that can be developed
into a computer program. Pseudocode is a generic way of describing an algorithm without use of
any specific programming language syntax. It is, as the name suggests, pseudo code —it cannot
be executed on a real computer, but it models and resembles real programming code, and is
written at roughly the same level of detail.

Advantages of Pseudocode
 Improves the readability of any approach. It’s one of the best approaches to start
implementation of an algorithm.
 Acts as a bridge between the program and the algorithm or flowchart. Also works as a
rough documentation, so the program of one developer can be understood easily when a
pseudo code is written out. In industries, the approach of documentation is essential. And
that’s where a pseudo-code proves vital.
 The main goal of a pseudo code is to explain what exactly each line of a program should
do, hence making the code construction phase easier for the programmer.
How to write a Pseudo-code?
1. Arrange the sequence of tasks and write the pseudocode accordingly.
2. Start with the statement of a pseudo code which establishes the main goal or the aim.

Example:
This program will allow the user to check
the number whether it's even or odd.
3. The way the if-else, for, while loops are indented in a program, indent the statements
likewise, as it helps to comprehend the decision control and execution mechanism. They
also improve the readability to a great extent.
Example:
if "1"
print response
"I am case 1"
if "2"
print response
"I am case 2
4. Use appropriate naming conventions. The human tendency follows the approach to
follow what we see. If a programmer goes through a pseudo code, his approach will be
the same as per it, so the naming must be simple and distinct.
5. Use appropriate sentence casings, such as CamelCase for methods, upper case for
constants and lower case for variables.
6. Elaborate everything which is going to happen in the actual code. Don’t make the pseudo
code abstract.
7. Use standard programming structures such as ‘if-then’, ‘for’, ‘while’, ‘cases’ the way we
use it in programming.
8. Check whether all the sections of a pseudo code is complete, finite and clear to
understand and comprehend.
9. Don’t write the pseudo code in a complete programmatic manner. It is necessary to be
simple to understand even for a layman or client, hence don’t incorporate too many
technical terms.

You might also like