0% found this document useful (0 votes)
5 views11 pages

Understanding Algorithms and Flowcharts

The document discusses algorithms and flowcharts, emphasizing their definitions, benefits, and limitations. It explains how algorithms serve as step-by-step solutions to problems and how flowcharts visually represent processes. Examples of both algorithms and flowcharts are provided to illustrate their applications and functionalities.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views11 pages

Understanding Algorithms and Flowcharts

The document discusses algorithms and flowcharts, emphasizing their definitions, benefits, and limitations. It explains how algorithms serve as step-by-step solutions to problems and how flowcharts visually represent processes. Examples of both algorithms and flowcharts are provided to illustrate their applications and functionalities.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Algorithms andFlowch

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

Flowcharts and their Symbols


e x c e l l e n t

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

definition, is a step-by-step solution to a given problem. It helps to define the


Algorithm, by definit
dules.
it into smaller modul
problem by breaking
solution to
a given

executed by computer are first translated into a comnitar


a
ns that are guage.
The language used hu
to any compute language.
algorithm may be changed
An
such as additions and subtractions and comnlioatod
is A Combination
of elementary steps,
mathematical calculations.

decide the strategies that


The algorithms also
that can be Info Hub
canbe used for solving a problem
converted into computer programs. So, there The word alqorithm is derived from the name of
can be more than one strategy or logic to solve a Persian mathematician, Abu Jafar Mohammed
a particular problem. Generally, the most ibn-Musa al-Khwarizmi taking the phonic
t is said that he
efficient algorithm is used to solve a problem. pronunciation of his surname. on two
had invented the steps of basic operations
decimal numbers!
Benefits of Algorithms
An algorithm has a number of benefits which are as follows:

eips t0 decide the strategy: A programming problem becomes casi


the help of an algorithm.
USeful reference: An algorithm acts as the starting point of reference forreal-il
problems.
37
Flex
lexibility: An algorit) can be translated into
path for decision making: Decision
y
desired
Easy
algorithm.
Debugging (finding and correcting
mal
king becomes comput
casie er
Easy to debug:
with the help of an algorithm. error)
error)eot
a
prog
program
Reuse: Predefined algorithms can be used within the he
Limitations of Algorithms
user-define
An algorithm. in spite of the several benefits, has some
limitations.
algorithmg
No proper syntax: An algorithm does not have are as fol
specific rula
not have proper syntaxes.
Non-standard representation: It 1s difficult to standardise and t
people can represent the same algorithm in lardise an algorithy
different wavs n. Dil
Examples of Algorith ms

The following are some examples of algorithms.


Example 1:
Example 2:
Write an algorithm to display the sum of two Write an
numbers whose values are 3 and 5 algorithm to
respectively. marks of a student accept
and disnla the t
Start Start.
Let the first
number be equal to 3.
3 Let the second number be
Accept the name of the
equal to 5. 3 Accept the marks of the student.
Add both the numbers. studens
Display the name.
5 Display the result.
5 Display the marks.
Stop.
Stop.
Example 3: Write an algorithm to
marks of two accept the Example 4: Write
subjects
and average marks.
and display the total area of a an
algorithm to frifrla
square.
1Start. Start.
2Accept the marks of the first Accept the length of the side, S
Accept the marks of the subject. AREA-S*S
second subject.
Calculate the total by adding the two. Display AREA.
Divide the total by 2. Stop.
Display the average.
Stop.
38
u s c r
of he
the program has o store the
Ihe
ma have complex add
e\amples, locations

ues inta ome


all
these memory

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

tively. it can also be written


as
right-handside,sideF-3.
number.

that the content of the


the

of This isisaa variable


let first
the tha
nts
reysents
lled by the variable on the lefi-hand
s t a t c s

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

agrammatic representation of the logi


is the
diag of the
A
fowchart

directhon Ahich the


in whic
control flows
in a program. A
flowchart may be problem. It shows
from
lett to right
and from top

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

perceive programn find easier


an
drawlable,
Writing

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

Fig. 3.3 Fig. 3.4

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.

Examples of Flowcharts with Explanation


Example 1: Draw a flowchart and explain the steps to convert hours into mnutes

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

Stop. Fig. 3.8

CONDITIONAL STATEMENTSs

fiowchart normally has sequential:access.


An algorithm or
a
execution of a statement
situations, the
But in certain The statement should be
Condition?
condition. False
depends on a particular condition is satisfied. These
that
executed only when True
conditional statements. In an
statements are asknown

algorithm, theyarerepresented by an IF condition followed


should be executed.
by the statements that
Fig. 3.9 Conditional branching having
If the condition is false, the control is branched to a later only True block statements
This is
part of the program thus eliminating those steps.
also known as jumping.

In an algorithm this is represented as:

False
TrueCondition?
False block of
True block of
statements
F conditional
expression is true> statements

THEN <statements for a true Common

condition> statements

ELSE <statements for


a false condition> Conditional
branching
False
Fig.
3.10 True and
both
having
.
NOTmal statements that
should be executed anyway statements
Example
1: Draw a flowchart to determine a student's
faled. The final grade is calculated as final
nal
passedor the
average ofgrade: and
Steps
fourur marks."
START
indiTheccateaterwhewhe
Start. yass ehe
Tirad
Accept MI, M2, M3, M4. Input MI,
M2, M3, M4/
GRADE(MI+M2+M3+M4)/4.
Grade (MI+M2+M3+M4V4
50) THEN
IF (GRADE
<

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

Display GREATER Print Ais EOUAL


Ston
GREATER/
Fig. 3.13
STOP

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

3. What among the (b) Algorithm (c) Program

(a) Start following is the last step of an algorithm (d) Stop 45


(c) Decision
(b) Display
bol is used
symbo, to ask a questionthat can be
4.
Which
fowchart

(b) Process () Decision


answvered in "
( a ) Terminal
rue and
containsany assignment to F
(d InputOpu
5
Which
tiowchart symbo
(b) Process
a
variable? alse
(a) Terminal
(c) Decision
whether
the follo
owing statements re True or False. (d) Input/
B.
State

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.

D. Answer the following questions.


1. State one use ofthe following:
(a) Decision box (b) Processing box
(c) Terminal box
(d) Flow lines (e) Steps of an algorithm
(f) Counter
2 Compare and contrast algorithms and flowcharts.
3. What are the conditions to be kept in mind while designing a flowchart?
4. Define looping. How can looping help while solving a problem?

E. Solve the crossword using the given clues.

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 ) .

for finding ous


number amono
f l o w c h a r t

find out the largest


and find
and
and
design
a
the
from the
keyboard
keyboard

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

continuation, data entry,


dISplay o
flow lines,
calculation, termination,
of boxes containing
ages
information and decision making are shown above.
m amatch
tch
ffow lines.
with flow lines.

above. For example,


1. Match the images with the names given
2. Give the number of lines flowing in and out of each box.
3. Give examples of statements of steps for each of the shown boxes.

You might also like