Flowcharts, Algorithms, and
Pseudocodes
A computer works by performing a list of instructions called computer programs. These are written by programmers using a
programming language. Programs are stored as a file on the hard drive when run
read by the computer, and the processor reads the data in the file as a list of
instructions. Everything a computer does is done by using a computer program.
It is very important for beginning computer programmers to understand the basic
principles of computer programming by learning flowcharts, algorithms, and
pseudocodes, which provides a step-by-step process in solving any programming
problems. Flowcharts,
algorithms, and pseudocodes make your program understandable and it helps you
write your program. But if you already understood, experienced, and good in
computer programming, it is not essential to write flowcharts, algorithms, and
pseudocodes for every program you are writing.
Algorithm
|
Input.
An algorithm may or may not require an 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.
The algorithm and flowchart
include following three types of control structures.
1. Sequence. In the sequence structure, statements are placed one
after the other and the execution takes place starting from up to down.
2. Branching (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.
3. Loop (Repetition). The
loop or repetition allows a statement(s) to be executed repeatedly based on
certain loop condition (e. g. WHILE, FOR
loops).
Advantages
of 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.
Disadvantages
of Algorithm
One disadvantage of algorithms
is that they always terminate, which means there are some computational
procedures - occasionally even useful ones - which are not algorithms.
Furthermore, all computational procedures, whether they terminate or not, can
only give computable results, so you cannot, for example, design a program,
which determines a busy beaver number more quickly than could be done by
actually running the associated types of turing machines.
How to
write an Algorithm?
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 the rectangle’s height and rectangle’s 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 the area of a 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 the area of a rectangle,
output will be the value stored in the variable AREA. If input variables
described a rectangle with a HEIGHT of 3 and a WIDTH of 4, the algorithm would
output the value of 12.
Pseudocode
Pseudocode is
a version of instructions describing each step the computer must follow. It is
written in an abbreviated form of spoken language and these lie somewhere in commands
written in ordinary English and those in a computer language.
Advantages
of Pseudocode
·
can
be done easily in a word processor
·
can
be easily modified compared to flowchart
·
implements
structured concepts well
·
clarifies
algorithms in many cases
·
imposes
increased discipline on the process of documenting detailed design
·
provides
additional level at which inspection can be
performed
·
helps
to trap defects before they become code
·
increases
product reliability
·
may
decrease the overall costs
·
Its
implementation is very useful in structured design elements.
·
It
can be written easily.
·
It
can be read and understood easily.
·
Converting
a pseudocode to programming language is very easy compared in converting a
flowchart to programming language
Disadvantages of Pseudocode
·
It is not visual.
·
creates an additional level of documentation to
maintain
·
introduces error possibilities in translating
to code
·
may require tool to extract pseudocode and
facilitate drawing flowcharts
·
There is no accepted standard, so it varies
widely from company to company.
·
We do not get a picture of the design.
·
There is no standardized style or format, so
one pseudocode may be different from the
other.
·
For a beginner, it is more difficult to follow
the logic or write pseudocode as compared to the flowchart.
Flowchart
The flowchart can help us view
the relationships between two or more parts and subparts of the program.
Moreover, it improves the clarity of our logical thoughts, since we had seen
its relationships with each other in graphical form. The computer program involves
three basic main operations:
Input (to enter data)
Process (to calculate or make choices)
Output
(to produce a result or
report)
Symbol
|
Name
|
Meaning
and Usage
|
Oval
|
Terminal
symbol
|
signifies
the start or end of a program
|
Parallelogram
|
Input/Output
symbol
|
indicates
where the data are to be entered or results to be displayed
|
Rectangle
|
Process
symbol
|
specifies
processing procedures that usually involve calculations
|
Diamond
|
Decision
symbol
|
denotes
a choice or decision to be made by the computer
|
Arrow Heads
|
Flow
lines
|
specifies
the sequence or order of instruction
|
Connector
|
Flow
connector
(On-Page
connector)
|
connects
various sub-parts of a flowchart. The circle may contain a number or a letter.
|
Hexagon
|
Initialization
symbol
|
initializes
or stores the first values of the variables.
|
Pentagon
|
Off-Page
connector
|
connects
the flowchart to the next page if it would not fit in one page
|
Flowchart
and Algorithm: Elements and Its Structure
Since the algorithm and flowchart
are guides and blueprints in order for us to design and develop computer
programs successfully, then the following structures and elements are also
applicable or “ready-to-apply” in the actual coding of our programs.
A. Constants - are literal values
that do not change during program execution. It can be of the numeric or string
data type.
Numeric
Constant. This may
be an integer (whole number) or a
real number (with a decimal point).
It may be preceded by a positive (+) or a negative (-) sign.
String
Constant. This is a character or group of characters
enclosed in double quotation marks (“)
or in some cases, in a single quote (‘).
Numbers 0 to 9, letters of the alphabet from A to Z and all special characters,
such as space, *, %, $, _, &, and many others are also considered as string constants if they are enclosed by
a pair of quotes.
B. Variables
- is a portion of the
computer’s main memory used to store a numeric or string constant. The value
stored in the variable must be given a unique variable name, and it can only
hold one value at a given time.
Variable names must conform to the following
requirements:
• must contain only letters, numbers, or an
underscore
• must begin with a letter
• must end either with a letter or a number
• must be unique that is, not the name of
another variable
• must not be any of the programming languages
keywords, such as for, while,
do, case, switch, if, else, default,
break, try, catch, finally, and many
others.
Operators
or Notations Used In Flowcharting
These logical operators were
originated and patterned from the formulas used to invent the computer itself.