Understanding Algorithms and Flowcharts
Understanding Algorithms and Flowcharts
generally
g e n e r a l l y
contains
c o n t a i n s
the Chapter Focus
cOok
a dishstep-by-step
dish approach
approach
Algorithms
stcp-by-step
to
r e c i p e
and
the
in a
cookb kbook Benefits and Pitfalls of
Examples of AlgorithmsAlgorithms
A
rec1pe
ingredients
ready.
A ellent example of
c
d i s h is
rea example
the
until as an also
nsidered
routin jobs a r e
jobs:
Benefits and Pitfalls of
be
dailyroutine
Our by us. Any
Any Examples of FlowchartsFlowcharts
may
algorithm. defined defined
a l g o r i t h m s
an
s o m e
executed
has a
basedon planned
and
that 1s
event
detined algorithm
A L G O R I T H M S
ariable.
A variable thus
refers to a ses. So for nto some memorN
memor
by assignment the ease f the user
h e s e
var
In a
catnons
toas these are represent
ars
these an
n e t e m d
1a/ucs.
In
algorihms,
cqual
to
may be written s Let F=3
3,
'mav
oCation tthathat cacan store
ent operators.
here [Link] aFor example.
be
ar7ngtirsI
number
that
the - that
nersentation
memorn o a t i o nl a b e l e d
arrow more
is scientific
ntif
stored to a
FLOWCHARIS
u s t be executed
must exe.
ttom, or a
sequenthe ial, which
stepsmight
might
only when
few
Whichme the
it enecutes
some
which
which m
steps
the logic of particular be repeated
a means
might
be
helptul in understanding
understa
problem. Once the condition is satisthere
a
fied. or
These
are
easier to write
the in any high-level
program
language. Hence, flowchart
it is
is
drawn,
drawn,
becomes
Is a must
hetter
be
forr documentation of a
complex program correct to say
a
fiowchart
that
usually
drawn using some standard dard symbols (Table
surn
Flowcharts are
3.1).
Table 3. Standard symbols of flowcharts
Name ofsymbol/box
Symbol Function
Terminal This indicates the start or end of a
program or a process.
Input/Output This is used for any
indicates that
Input/Output (/0) operation. It
the computer is
supposed to
from input devices or give a result to the accept data
output device.
Process This indicates any type of internal
operation
inside the
processor or memory.
Decision This is used to ask a question that can be answered in a
binary format (For example, True/False, Yes/No, and
so on).
Flow lines These are used to show the flow of a program.
or an interrupt
This is used to invoke a
sub-program
Pre-defined Process
program.
without intersecting
flowchart to be drawn
Connector This allows the
reverse fow.
without a
the flow lines or
39
The following points should be kept in mind
vhile
The different clements should be joined a awing
Fach flowchart should by arrows
logically start and finih andan not flowchart
h
by t
Only one
Start box has
flow line
one
is
line
used
flowing
in a
terminal box, he
outof it, whereas
simple lines
Stop box has only one line the
flowing into it
Fig. 3.1).
(a) Start box
The Process box or
Input/Output box should have
input line and only one output line. only one
one Fig. 3.1
The Decision box has [Link] input and two
(Fig. 3.2). output lines
The connectorsymbol should be used to
a complex flowchart. It
may also be used to
simplify
the flowchart if exceeds a page.
it continue
alse
Confusion regarding the flow of control can be Fig. 3.2 Decision
of flow lines. decreasedb avoiding the
The flowchart should be tested once with
the iinterse
sample data.
Benefits of Flowcharts
Flowcharts have several benefits which are as
follows:
Easier to understand: Since a
flowchart
understand or make others represents solution pictorially,
a
nuch easier to
understand about the
Planning: A flowchart is used for progam [Link]
deciding initial planning ofa
the
Smaller processes: The initial flowchart can
be later broken
project
processes. These smaller processes may be elaborated later down into smaller naller
each. It can also help to join several smaller with separate
flowchar.
into aprocesses complete solution.
Makes programming easy: It makes
programming easy for the programmer as the
strategy is already decided. It also ensures the
Lesser time: Lesser
completeness of a program.
time consumed for writing an error-free program.
is
Testing and debugging: A flowchart
helps in the systematic testing of the logic
different combination of
inputs. It is also very useful for detecting, locating and wi
removing the errors of a program.
Limitations of Flowcharts
Flowcharts also suffer from some limitations which are as follows:
NOStandardisation:
The
Flowcharts do not have astandardised rule for representano
amount
of details may vary from one flowchart to the other.
ne
consuming: It is time consuming to draw a flowchart.
40
COMPARISON
B E T W E E N T W E E NA A
LG OR
L G OI
R TIH ITHMS AND FLOWCHART
list
« d o u n .
dvantages
advann
of
algorithms over flowcharts
oints
Table 3.2 Advantages of algorithms and flowchharts ondd Vice vera
ing
tollon
The
Flowcharts
antages of
Agorithms
over
consuming
The graphieal Flo wehar ts
representation of over
problAlemigoris iavailat
thms
ol
Advantages
less
time
whieh most a
algonthm
is
to
and does
not involve lowchart has abetter and
Aherations
can
the
be
entire
made
structure
casily
algorithms standardisation as
compared to
changing
E x a m p l e so f F l o w c h a r t s
examples
offlowc
of flowcharts.
some
are
The
following
to add Example 2: Draw a
Example
1: Draw
a
tlowchart
flowchart
and age of a to
accept the
twO numbers.
student and name
START START
it. display
lnput A, B
nput Niame
Input Age
C-AB
Print Name
Print
Print Age
STOP STOP
ln these examples, the flowchart starts with a Start (Terminal) symbol and has an VOutput
box to accept data from the user. Depending on the requirement of the problem, it either
processesand does calculation (Example ) or simply prints the data (Example 2). A flowchart
always ends with the Stop (Terminal) symbol. The direction of flow and the types of symbols
used for each kind of operation is important while drawing a flowchart.
Steps Explanation
is entered by the
user.
START
Start. First, the value in hours The value of
The variable H stores the input.
Input Hours, H the
with 60 to get
Accept hours, H. His then multiplied stored in a
value is
Min-H60 minutes. This
Min-H"60. cquivalent
variable called
Min and displayed
to the user.
Print Min an
Display Min. Based on the same logic, you
can
to
wrile
convert
flowchart
6Stop. STOP
Fig. 3.5
algorithm and draw
minutes into hours.
a
flowchart and explain
ffowchart
and e the
aa
2:
: Draw
Draw
nto Fahrenheit.
Fahrenheit.
E x a m p l e
into
Celsiu
convert
to
steps
START
Steps
Start.
Input C
Be aTechie
There are several
Accept C. advanced fn.
symbols hat are used
F-(95C)+32
F-(9/5*C)+32
[Link] view
all
Microsoft Word 2010.
to
theses onchon
depie
ict comper
se sumbos,th
Print F
Illustrations Shapes. ClickPlace
Display F
pointer on each
symbol Ploce IthnesenMG
get their name. under f
Stop
STOP
Fig. 3.6
owchor
Explanation
the value oftemperature in Celsius is entered by the user. The var:aL1
The oiven value is then used to get the equivalent temperature in Fahre eC stores
the j
used is F = (9/5*C) + 32. This value is stored in a variable called F:
and displayed to
canwrite an
algorithm and draw a flowchart to
tthehe we
Based on the same logic, you
into Celsius. Note:
C (F -32)*5/9]=
convert FaB
Fyample 3: Draw a flowchart and explain the steps to display the formula
of simnla:
interes
Steps Explanation
Start. First the value of
START principal, rate and t
are entered by the user
and stored in
Accept P.
Input P different variables P, R and T. The t
fom
Accept (P*R*T)/100 is used to calculate t
Accept Input R simple interest. This value is stored int.
variable SI which is later displayed.
SI-(P*R*T)/100. Input T
Display SI.
Stop. SI= (P*R*T)/100
Print SI
STOP
Fig. 3.7
42
the steps to interchange
nlain the
aand
fowchart
chart
nd
ex explain
the value of twoNO varivables
mpk
4:
Draw
a
varvable
t h i r d
Explanation variable
In this
problem, the
a
using
START
b
is stored in the value of the
third [Link]
Starn.
InputA , B of the second
variab is Then thevariable
variable. Now, the stored into value
AcceptA. value of the the
T-A is stored into the
second third first variable
Accept B sequence, the values are variable. Thus,, Inin this
T-A
A-B swapped.
B-T
A - B .
B-T.
Print A, B
DisplayA. B.
STOP
CONDITIONAL STATEMENTSs
False
TrueCondition?
False block of
True block of
statements
F conditional
expression is true> statements
condition> statements
Display FAIL
Is
ELSE
Display PASS.
Grade<502 Tue PrintFAL
False
ENDIF
Print PASS
5 Stop.
STOP
nple 2: Draw a flowchart to display whethertthe Fig. 3.11
number entered
negative. by the use
START is positig
Steps
Start. Input number,
NUM
Accept number, NUM.
IF (NUM>0) THEN
Is True
Display POSITIVE. Print
NUM> 0?
ELSE
/POSITIVE
False
Display NEGATIVE. Print
ENDIF NEGATIVE,
Stop STOP Fig. 3.12
Example 3: Draw a flowchart to
they are equal. display the greater of two numbers. Give a proper mesS
Steps
Start.
Accept A.
Accept B.
IFA>B THEN
44
START
GREATER
A
is
Input A, B
Display
R A T 7 H E N
GREATER
Is
Display
B is
=13? Irue Is
I F A BTHEN
A B?
E Q U A L
False
Print B is
Truc
Print
Both are
False
are
Borh
ech Bytes
tion
solutio to a giver
gorithm:
a step-by-step
Flowchart:
of an algorithm s******ss****ssasamaen
the
diagrammatic representation
A g o r
problem
the language
used by an
Pseudo-code:
.
Loop: refers to a
structure that
execute certain steps
algorithm
location that can store of a helps to
.Variable: a memory Counter: variable that program repeatedly
a
varying values
number of keeps
times a loop a
track of
gets executed the
Bits to Remember
ln order to design software
a or a
program, the
problem has to be identified
first.
/ Afier defining the problem, the strategy for solving the same has to be defined
Afowchart helps to identify and solve the problem pictorially.
Analgorithm defines the solution ofthe problem step-by-step.
The representation of an algorithm is not standardised.
Somepredefined symbols are used in flowcharts to represent specific processes.
Conditional statements refer to those statements which branch out in different directions based on the
logic of the program.
Loops help to execute few lines of code repeatedly without rewriting them.
ASSESSMENT ZONE
A. Choose the correct
answer.
Which of the
following symbols has only one flow line (d) Start
(a) Process (c) Decision
2. (b) Input
What do you call
(a) Flowchart
a
graphical representation of logic? (d) Pseudo-code
1. Thealgorithm
fiowchart helps us
should be written afte writing
the code.
to understand the problem in a better way.
IOutput
make the flowchart sequential
Conditional statements
the programmer to branch to several directionis.
Looping helps
flowchart is taster than writing an algorithm.
s Drawingg a
the words given in the box.
[Link] in the blanks using
Variable Conditional Counter Loop
1 The variable that keeps a track of number of times a loop gets executed is
Connecto
box is used in. statements.
2 A decision
is a memory location that can store varying values.
sVmbol is used to draw a fiowchart without
intersecting the flow lines.
5. A single line may
be executed repeatedly using a.
Crossword Zone
ACROSSs
3. A step-by-step solution to a given problen
5. Last symbol of a flowchart
I
6. Memory location that can store varying
values
8. Structure that forms repetitive task
DOWN
1. Diagrammatic representation oflogic
2. First of a flowchart
symbol
two or three outpuls
4. Box that contains
IF condition
7. Block following the
46
number of bytes and convert that
to accept the
flow gigabytes (1024 megabytes)
and
design
a kilobytes),
a l g o r i t h m
and
gabytes
m e g a b y t e s
(1024
(1024
an bytes),
1.
Write
(1024
finding the are
a eaa
ofa rectangle.
kilobytes
t e r a b y t e s
into
( 1 0 2 4 g i g a b y t e s ) .
n u m b e r s
algorithnm
an three equal.
read not
the equivalen
Write
to are
and find out
2. n u m b e r s
a subject
student in
f l o w c h a r t
a three
Draw
that the ohtained by a
3. A s s u m e
marks ts o bt
them. read
f l o w c h a r t
to
a
below: Grade
Draw given
4. criteria
Marks
using
the A
>=80
B
8 0 and >=60
<60 and >=40 C
Fail
40
mage
Stud
INPUT
START
IF
CONDITION
STOP
PROCESSS N
OUTPUT
A