0% found this document useful (0 votes)
2 views

Control structure

The document provides an overview of algorithms and control structures in computer science, defining algorithms as finite sets of instructions to accomplish specific tasks. It explains the properties that every algorithm must satisfy, such as input, output, definiteness, finiteness, and correctness. Additionally, it details three types of control structures: sequential logic, selection logic, and iteration logic, each with their respective characteristics and examples.

Uploaded by

ashakrishnan1976
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Control structure

The document provides an overview of algorithms and control structures in computer science, defining algorithms as finite sets of instructions to accomplish specific tasks. It explains the properties that every algorithm must satisfy, such as input, output, definiteness, finiteness, and correctness. Additionally, it details three types of control structures: sequential logic, selection logic, and iteration logic, each with their respective characteristics and examples.

Uploaded by

ashakrishnan1976
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Rammurt

iEducat
ionSoci
ety'
s
St
.Xav
ier
s’Engli
shHi
ghSchool&Jr.Col
lege,
Manpada,
Thane(
w)

Subject:
-ComputerSci
ence–I
Topic–Dat aStr
uct
ure
Probablemarks–17
Lecture-2(
Notes)

Whati
sanAl
gor
it
hm ?
Analgorit
hm isafi
nit
esetofinst
ruct
ionsorl
ogi
c,wr
itt
eninor der
,toaccompli
shacert
ain
predef
inedtask.Al
gori
thm i
snotthecomplet
ecodeorprogram, i
tisj
ustthecorel
ogi
c(sol
uti
on)
ofaproblem,whichcanbeexpressedeit
herasani
nformalhighlevel
descri
pti
on
aspseudocodeorusingaf l
owchart.
Ev
eryAl
gor
it
hm mustsat
isf
ythef
oll
owi
ngpr
oper
ti
es:

1.I
nput
-Ther
eshoul
dbe0ormor
einput
ssuppl
i
edext
ernal
l
ytot
heal
gor
it
hm.
2.Out
put
-Ther
eshoul
dbeat
least1out
putobt
ained.
3.Def
ini
teness-Ev
eryst
epoft
heal
gor
it
hm shoul
dbecl
earandwel
ldef
ined.
4.Fi
nit
eness-Theal
gor
it
hm shoul
dhav
efi
nit
enumberofst
eps.
5.Cor
rect
ness-Ev
eryst
epoft
heal
gor
it
hm mustgener
ateacor
rectout
put
.

Anal
gori
thm i
ssai
dtobeef
fi
cientandf
ast
,ifi
ttakesl
esst
imet
oexecut
eandconsumesl
ess
memoryspace.

Whati
sanCont
rol
Str
uct
ure?
Acont r
olstructur
eisli
keablockofpr ogr
ammi ngthatanal
ysesvar
iabl
esandchoosesa
dir
ecti
oni nwhichtogobasedongi venparameters.Theter
mf l
owcontroldet
ail
sthedirect
ion
theprogram takes(whi
chwaypr ogr
am control"f
lows")
.Henceiti
sthebasicdeci
sion-
making
processincomput i
ng;I
tisapredict
ion.
OR
ControlStructuresarejustawayt ospecif
yflowofcontroli
nprograms.Anyalgor
ithm or
progr
am canbemor ecl
earandunder st
oodiftheyuseself
-cont
ainedmodulescal
ledaslogi
cor
contr
ol st
ructures.Itbasi
cal
lyanalyzesandchoosesinwhichdirecti
onaprogram f
lowsbased
oncertainparamet ersorcondi
tions.

Ther
earethreebasi ctypesoflogi
c,orf
lowofcont
rol
,knownas:
1.Sequencelogi c,orsequenti
alfl
ow
2.Select
ionlogic, orcondi
ti
onalfl
ow
3.Iter
ati
onlogic, orrepet
it
ivefl
ow
Letusseet
hem i
ndet
ail
:
1.SequentialLogic(
SequentialFl
ow)
Sequentiall
ogicasthenamesuggest sfoll
owsaser i
alorsequent
ialf
lowinwhi chthefl
ow
dependsont heseri
esofinstruct
ionsgiventothecomput er
.Unl
essnewi nst
ructi
onsare
gi
ven, t
hemodul esareexecutedintheobvioussequence.Thesequencesmaybegi v
en,by
meansofnumber edstepsexpli
cit
ly.Al
so,impli
ci
tl
yfoll
owst heor
derinwhichmodul esare
wri
tten.
“Al
gor
it
hm”
.
.

Modul
eA

Modul
eB

Modul
eC


Flowchar
t”

2.Sel
ecti
onLogic( Condit
ionalFlow)
Sel
ecti
onLogicsimpl yi
nvolvesanumberofcondi
ti
onsorparameter
swhichdeci
desone
outofsever
alwr i
ttenmodules.Thest
ruct
ureswhi
chusethesetypeofl
ogicar
eknown
asCondit
ionalStructur
es.
Thesestr
ucturescanbeoft hreety
pes:
 Si
ngl
eAl
ter
nat
ive:
-

“Al
gor
it
hm”
I
f(condi
ti
on)t
hen:
[
Modul
eA]
[
EndofI
fst
ruct
ure]


Flowchar
t”

 Doubl
eAl
ter
nat
ive:
-
“Al
gor
it
hm”

I
f(Condi
ti
on)
,then:
[
Modul
eA]
El
se:
[
Modul
eB]
[
Endi
fst
ruct
ure]


Flowchar
t”
 Mul
ti
pleAl
ter
nat
ives:
-
“Al
gor
it
hm”

I
f(condi
ti
onA)
,then:
[
Modul
eA]
El
sei
f(condi
ti
onB)
,then:
[
Modul
eB]
.
.
.
.
El
sei
f(condi
ti
onN)
,then:
[
Modul
eN]
[
EndI
fst
ruct
ure]

Int
hisway
,thefl
owofthepr
ogr
am dependsonthesetofcondi
ti
onst
hatar
ewr
it
ten.Thi
s
canbemoreunderst
oodbyt
hefol
l
owingflowchar
ts:

3.It
erat
ionLogic(Repet
it
iv eFl
ow)
TheIt
erat
ionlogicemploy sal
oopwhi
chi
nvol
vesar
epeatst
atementf
oll
owedbyamodul
e
knownast hebodyofal oop.

Thet
wot
ypesofthesestr
uctur
esar
e:
 Repeat
-ForStr
uctur
e

“Al
gor
it
hm”

Repeatf
ori
=At
oNbyI
:
[
Modul
e]
[
Endofl
oop]

Flowchar
t”
Repeat
-Whi
leSt
ruct
ure

 Repeatwhi
l
e(condi
ti
on)
:
 [
Modul
e]
 [
Endofl
oop]

You might also like