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

Problem Solving

Uploaded by

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

Problem Solving

Uploaded by

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

Feder

alUni
ver
sit
yDut
se
Fac
ult
yOfSc
ience
Depar
tmentOfComputerSc
ienc
e

CSC102:I
ntr
oduc
tionToProbl
emSol
vi
ng(
3Uni
ts)
Lectur
eNote

1
Chapt
erOne(
1)Gener
alI
ntr
oduc
ti
on
1.
1Whati
saFor
mal
Probl
em?
Us
ual
l
ythet
erm pr
obl
em i
sus
edt
oref
ert
oas
ituat
ionwher
eiti
s
noti
mmedi
atel
yobvi
oushowt
oreac
hthegoal
.Theex
acts
ame
s
ituat
ionc
anbeapr
obl
em f
oroneper
sonandnotapr
obl
em
(
per
hapsj
ustas
impl
eac
ti
vi
tyorr
out
ineex
erc
ise)f
oranot
her
per
son.Pr
obl
em s
olvi
ngc
ons
ist
sofmovi
ngf
rom agi
veni
ni
ti
al
s
ituat
iont
oades
iredgoal
sit
uat
ion.Thati
s,pr
obl
ems
olvi
ngi
sthe
pr
oces
sofdes
igni
ngandc
arr
yingoutas
etofs
tepst
oreac
ha
goal
.
Tos
olvet
hepr
obl
em,y
ouneedt
otr
avelf
rom as
tar
ti
ngpoi
nt,
c
all
edt
hei
ni
ti
als
tat
e,t
oanendpoi
nt,c
all
edt
hegoals
tat
e.The
i
ni
ti
als
tat
einc
ludesal
loft
he knowl
edge and r
esour
cesy
ou
c
urr
ent
lyhaveavai
l
abl
e.Thegoal
stat
eref
erst
othes
olut
iont
hat
y
ouwantt
oreac
h.Thes
etofpos
sibl
eway
stot
ravelf
rom t
he
i
ni
ti
als
tat
etot
hegoal
stat
eisc
all
edt
hepr
obl
ems
pac
e.

2
Fi
gur
e1.Pr
obl
em-
sol
vi
ngpr
oces
s--
howt
oac
hievef
inal
goal
?

Pr
obl
em-
sol
vi
ngi
sat
ool
,as
kil
l
,andapr
oces
s.Asat
ool
ishel
ps
y
ous
olveapr
obl
em orac
hieveagoal
.Asas
kil
lyouc
anus
eit
r
epeat
edl
ythr
oughouty
ourl
i
fe.And,asapr
oces
siti
nvol
vesa
numberofs
teps
.Pr
obl
em-
sol
vi
ng i
s a ment
alpr
oces
sthat
i
nvol
ves di
scover
ing,anal
yzi
ng and s
olvi
ng pr
obl
ems
. The
ul
ti
mat
egoalofpr
obl
em-
sol
vi
ngi
stoover
comeobs
tac
lesand
f
indas
olut
iont
hatbes
tres
olvest
hei
ssue. Thebes
t
s
trat
egyf
ors
olvi
ngapr
obl
em dependsl
argel
yont
heuni
que
s
ituat
ion.I
nsomec
ases
,peopl
ear
ebet
terof
flear
ningever
ythi
ng
t
heyc
anaboutt
hei
ssueandt
henus
ingf
act
ualknowl
edget
o
c
omeupwi
thas
olut
ion.I
not
heri
nst
anc
es,c
reat
ivi
tyandi
nsi
ght
ar
ethebes
topt
ions
.

1.
2Pr
obl
emSol
vi
ngi
nEver
ydayLi
fe
Peopl
emakedec
isi
onsever
ydayt
osol
vepr
obl
emst
hataf
fec
t
t
hei
rl
ives
.Thepr
obl
emsmaybeasuni
mpor
tantaswhatt
owat
ch
ont
elevi
si
onorasi
mpor
tantasc
hoos
inganewpr
ofes
sion.I
fa
bad dec
isi
oni
smade,t
imeand r
esour
cesar
ewas
ted,s
oit
’s
i
mpor
tantt
hatpeopl
eknow how t
omakedec
isi
onswel
l
.Ther
e

3
ar
esi
xst
epst
ofol
l
ow t
oens
uret
hebes
tdec
isi
oni
nmaki
ng
pr
obl
em s
olvi
ngasapr
oces
s.Thes
esi
xst
epsi
npr
obl
em s
olvi
ng
i
ncl
udet
hef
oll
owi
ng:
1.
2.1I
dent
if
ythe pr
obl
em.The f
ir
sts
tep t
owar
dsol
vi
ng a
pr
obl
em i
stoi
dent
if
ythepr
obl
em.I
nac
las
sroom s
ituat
ion,mos
t
pr
obl
emshavebeeni
dent
if
iedf
ory
ouandgi
vent
oyoui
nthe
f
ormofwr
it
tenas
signment
sorpr
obl
emsoutofabook.However
,
wheny
ouar
edoi
ngpr
obl
em s
olvi
ngout
sidet
hec
las
sroom,y
ou
needt
omakes
urey
oui
dent
if
ythepr
obl
em bef
orey
ous
tar
t
s
olvi
ngi
t.I
fyoudon’
tknowwhatt
hepr
obl
emi
s,y
ouc
annots
olve
i
t.
1.
2.2Under
stand t
he pr
obl
em.Youmus
tunder
stand whati
s
i
nvol
ved i
nthe pr
obl
em bef
orey
ouc
an c
ont
inue t
owar
dthe
s
olut
ion.Thi
sinc
ludesunder
standi
ngt
heknowl
edgebas
eoft
he
per
sonormac
hinef
orwhom y
ouar
esol
vi
ngt
hepr
obl
em.I
fyou
ar
eset
ti
ngupas
olut
ionf
oraper
son,t
heny
oumus
tknowwhat
t
hatper
sonknows
.Adi
ff
erents
etofi
nst
ruc
ti
onsmi
ghthavet
o
beus
eddependi
ngont
hisknowl
edgebas
e.
1.
2.3I
dent
if
yal
ter
nat
ive way
sto sol
ve t
he pr
obl
em.Thi
sli
st
s
houl
dbeasc
ompl
eteaspos
sibl
e.Youmi
ghtwantt
otal
kto
ot
herpeopl
etof
ind ot
hers
olut
ions t
han t
hos
eyou have
i
dent
if
ied.Al
ter
nat
ive s
olut
ionsmus
tbe ac
cept
abl
e ones
.You
c
oul
d go f
rom Dut
set
o JosbywayofKano,butt
hiswoul
d
pr
obabl
ynotbeanac
cept
abl
esol
uti
ont
oyourt
ravel
needs
.
4
1.
2.4Sel
ectt
hebestwayt
osol
vet
hepr
obl
em f
rom t
hel
i
stof
al
ter
nat
ive sol
uti
ons
.Int
hiss
tep,y
ou need t
oident
if
y and
eval
uat
ethe pr
osand c
onsofeac
hpos
sibl
esol
uti
onbef
ore
s
elec
ti
ngt
hebes
tone.I
nor
dert
odot
his
,youneedt
osel
ect
c
ri
ter
iaf
ort
he eval
uat
ion.Thes
ecr
it
eri
a wi
l
lser
ve as t
he
gui
del
i
nesf
oreval
uat
ingeac
hsol
uti
on.
1.
2.5Li
sti
nst
ruc
tionst
hatenabl
eyout
osol
vet
hepr
obl
emusi
ng
t
hesel
ect
edsol
uti
on.Thes
enumber
ed,s
tep-
by-
stepi
nst
ruc
ti
ons
mus
tfal
lwi
thi
nthe knowl
edge bas
esetup i
nst
ep 2.No
i
nst
ruc
ti
onc
anbeus
edunl
esst
hei
ndi
vi
dualort
hemac
hinec
an
under
standi
t.Thi
scanbever
yli
mit
ing,es
pec
ial
l
ywhenwor
king
wi
thc
omput
ers
.
1.
2.6Eval
uat
ethesol
uti
on.Toeval
uat
eort
estas
olut
ionmeans
t
ochec
kit
sres
ultt
oseei
fi
ti
scor
rec
t,andt
oseei
fi
tsat
isf
iest
he
needsoft
heper
son(
s)wi
tht
hepr
obl
em.(
Whenaper
sonneeds
api
eceoff
urni
tur
etos
leepon,
buy
i otmaybeac
ngherac orr
ect
s
olut
ion,buti
tmaynotbever
ysat
isf
act
ory
.)I
fther
esul
ti
sei
ther
i
ncor
rec
toruns
ati
sfac
tor
y,t
hent
hepr
obl
em s
olvermus
trevi
ew
t
hel
i
stofi
nst
ruc
ti
onst
oseet
hatt
heyar
ecor
rec
tors
tar
tthe
pr
oces
sal
loveragai
n.
I
fanyoft
hes
esi
xst
epsar
enotc
ompl
etedwel
l
,ther
esul
tsmay
bel
esst
handes
ired.Peopl
esol
vepr
obl
emsdai
l
yathome,or
wor
k,orwher
evert
heygo.Pr
obl
emsathomei
ncl
udes
ucht
hings
aswhatt
ocookf
ordi
nner
,whi
chmovi
etos
eet
hiseveni
ng,
whi
ch
5
c
art
obuy
,orhowt
osel
lt
hehous
e.Atwor
k,t
hepr
obl
emsmi
ght
i
nvol
vedeal
i
ngwi
thf
ell
owempl
oyees
,wor
kpol
i
ci
es,
management
,
orc
ust
omer
s.Thebet
tert
hedec
isi
onsanempl
oyeec
anmake,
t
hemor
eval
uabl
ethatper
sonwi
l
lbet
othec
ompany
.Ineac
h
c
ase,t
he s
ixs
tepsi
npr
obl
em s
olvi
ng c
anbe f
oll
owed.Mos
t
peopl
eus
ethemwi
thoutevenknowi
ngi
t.

1.
3The4st
epsi
nusi
ngaComput
erasaPr
obl
emSol
vi
ngTool
- Devel
opanAl
gor
it
hmandaFl
owc
har
t.
- Wr
it
ethepr
ogr
ami
nac
omput
erl
anguage.(
i.
e.JavaorC++,
Ent
ert
hepr
ogr
ami
ntot
hec
omput
er.
- Tes
tanddebugt
hepr
ogr
am.
- Runt
hepr
ogr
am,i
nputdat
a,andgett
her
esul
tsf
rom t
he
c
omput
er.

1.
4Ty
pesofPr
obl
ems
Br
oadl
yspeaki
ng,t
wo(
2)maj
ort
ypesofpr
obl
emshave been
r
ecogni
zed:Al
gor
it
hmi
corHeur
ist
ici
nnat
ure.
1.
4.1Al
gor
it
hmi
c
Pr
obl
emsdonotal
way
shaves
trai
ghtf
orwar
dsol
uti
ons
.Some
pr
obl
ems
,suc
hasbal
anc
ingac
hec
kbookorbaki
ngac
ake,c
an
bes
olved wi
thas
eri
esofac
ti
ons
.Thes
esol
uti
onsar
ecal
l
ed
al
gor
it
hmi
csol
uti
ons
.Onc
etheal
ter
nat
iveshavebeenel
i
minat
ed,
f
orex
ampl
e,andonc
eonehasc
hos
ent
hebes
tamongs
ever
al

6
met
hodsofbal
anc
ingt
hec
hec
kbook,
thes
olut
ionc
anber
eac
hed
byc
ompl
eti
ngt
heac
ti
onsi
nst
eps
.Thes
est
epsar
ecal
l
edt
he
al
gor
it
hm.
1.
4.2Heur
ist
ic
Thes
olut
ionsofot
herpr
obl
ems
,suc
hashow t
obuyt
hebes
t
s
toc
k or whet
her t
o ex
pand t
he c
ompany
, ar
e not s
o
s
trai
ght
for
war
d.Thes
esol
uti
ons r
equi
rer
eas
oni
ng bui
l
t on
knowl
edge and ex
per
ienc
e.Sol
uti
onst
hatc
annotbe r
eac
hed
t
hroughadi
rec
tsetofs
tepsar
ecal
l
edheur
ist
ics
olut
ions
.
Thepr
obl
ems
olverc
anus
ethes
ixs
tepsf
orbot
hal
gor
it
hmi
cand
heur
ist
ics
olut
ions
.However
,ins
tep6,
eval
uat
ingt
hes
olut
ion,
the
c
orr
ect
nes
sandappr
opr
iat
enes
sofheur
ist
ics
olut
ionsar
efarl
ess
c
ert
ain.I
t’
seas
ytot
elli
fyourc
ompl
etedc
hec
kbookbal
anc
eis
c
orr
ectands
ati
sfac
tor
y,buti
t’
shar
dtot
elli
fyouhavebought
t
hebes
tst
ock. Wi
thheur
ist
ics
olut
ions
,thepr
obl
em s
olverwi
l
l
of
ten need t
ofol
l
ow t
he s
ixs
tepsmor
ethan onc
e,c
aref
ull
y
eval
uat
ingeac
hpos
sibl
esol
uti
onbef
oredec
idi
ngwhi
chi
sbes
t.

1.
5Pr oblemsandObstacl
esinProbl
em-
Solvi
ng
Ofcourse,pr
oblem-
sol
vingisnotaperf
ectproc
ess
.Ther
ear
ea
numberofdi
ff
erentobs
tac
lest
hatc
ani
nter
fer
ewi
thourabi
l
it
yto
s
olve a pr
obl
em qui
ckl
y and ef
fi
ci
ent
ly
.Res
ear
cher
s have
des
cri
bed a numberoft
hes
e ment
alobs
tac
les
,whi
chi
ncl
ude
f
unc
ti
onal
fi
xednes
s,i
rr
elevanti
nfor
mat
ionandas
sumpt
ions
.

7
1.
5.1Func
tionalFi
xedness:Thi
ster
mref
erst
othet
endenc
yto
vi
ew pr
obl
ems onl
yint
hei
rcus
tomar
y manner
.Func
ti
onal
f
ixednes
spr
event
speopl
efr
om f
ull
yseei
ngal
loft
hedi
ff
erent
opt
ionst
hatmi
ghtbeavai
l
abl
etof
indas
olut
ion.

1.
5.2I
rr
elevantorMi
sl
eadi
ngI
nfor
mat
ion:Wheny
ouar
etr
yingt
o
s
olveapr
obl
em,
iti
simpor
tantt
odi
sti
ngui
shbet
weeni
nfor
mat
ion
t
hati
srel
evantt
othei
ssueandi
rr
elevantdat
athatc
anl
eadt
o
f
aul
tys
olut
ions
.Whenapr
obl
em i
sver
ycompl
ex,t
heeas
ieri
t
bec
omest
ofoc
usonmi
sl
eadi
ngori
rr
elevanti
nfor
mat
ion.

1.
5.3Assumpt
ions
:Whendeal
i
ngwi
thapr
obl
em,peopl
eof
ten
make as
sumpt
ions aboutt
he c
ons
trai
nts and obs
tac
les t
hat
pr
eventc
ert
ains
olut
ions
.

1.
5.4Ment
alSet
:Anot
herc
ommonpr
obl
em-
sol
vi
ngobs
tac
lei
s
knownasament
als
et,
whi
chi
sthet
endenc
ypeopl
ehavet
oonl
y
us
esol
uti
onst
hathavewor
kedi
nthepas
trat
hert
hanl
ooki
ngf
or
al
ter
nat
ivei
deas
.Ament
als
etc
anof
tenwor
kasaheur
ist
ic
,
maki
ngi
taus
eful
probl
em-
sol
vi
ngt
ool
.However
,ment
als
etsc
an
al
sol
eadt
oinf
lex
ibi
l
it
y,maki
ngi
tmor
edi
ff
ic
ultt
ofi
ndef
fec
ti
ve
s
olut
ions
.

1.
6PROBLEM

Namet
hreec
urr
entpr
obl
emsi
nyourl
i
fet
hatc
oul
dbes
olved

8
t
hrough an al
gor
it
hmi
c pr
oces
s.Ex
plai
n why eac
h oft
hes
e
pr
obl
emsi
sal
gor
it
hmi
cinnat
ure.

Compl
etet
hes
ixpr
obl
em-
sol
vi
ngs
tepst
osol
veoneoft
he
pr
obl
emsy
oul
i
stedi
n
ques
tion1.Fol
l
owt
hef
ormout
li
nedasf
oll
ows
:
St
ep1:I
dent
if
ythepr
obl
em.
St
ep2:Under
standt
hepr
obl
em.
a.Comment
saboutt
hepr
obl
emt
oai
dinunder
standi
ngi
t.
b.Des
cri
pti
onoft
heknowl
edgebas
e(t
hisl
i
stwoul
dinc
ludewhat
y
ou
woul
dbeex
pec
tedt
oknowt
ofol
l
owt
hes
olut
ion)
.
St
ep3:I
dent
if
yal
ter
nat
ives
olut
ions
.
Sol
uti
onPr
osCons
a.
b.
c.
.
.
.
St
ep4:Sel
ectt
hebes
tsol
uti
on.
Whydi
dyous
elec
tthi
ssol
uti
on?
St
ep5:Li
stas
etofnumber
eds
tep-
by-
stepi
nst
ruc
ti
onst
oat
tai
n
t
hes
olut
ion.
1.
2.
3.

9
.
.
St
ep6:Testt
hes
olut
ion.
Doest
hiss
olut
ionwor
k?I
fnot
,howmi
ghty
ouc
hanget
hes
olut
ion
s
oitwi
l
lwor
k

Chapt
erTwo(
2)Pr
obl
em-
Sol
vi
ngSt
rat
egi
es

2.
1Pr
obl
em-
Sol
vi
ngSt
rat
egi
es

As
trat
egyc
anbet
houghtofasapl
an,
aheur
ist
ic
,ar
uleoft
humb,
apos
sibl
ewayt
oappr
oac
hthes
olvi
ngofs
omet
ypeofpr
obl
em.
Forex
ampl
e,per
hapsoneoft
hepr
obl
emst
haty
ouhavet
odeal
wi
thi
sfi
ndi
ngapar
kingpl
aceatwor
korats
chool
.I
fso,
probabl
y
y
ouhavedevel
opedas
trat
egy
--f
orex
ampl
e,apar
ti
cul
art
imeof
daywheny
oul
ookf
orapar
king pl
aceorapar
ti
cul
ars
ear
ch
pat
ter
n.Yours
trat
egymaynotal
way
sbes
ucc
ess
ful
,buty
ouf
ind
i
tus
eful
.

Ever
ypr
obl
em-
sol
vi
ngdomai
nhasi
tsowns
trat
egi
es.Bel
ow ar
e
s
omeoft
hes
trat
egi
esus
edi
npr
obl
ems
olvi
ng

2.
1.1Al
gor
it
hms
:Pr
obl
emsdonotal
way
shaves
trai
ghtf
orwar
d
s
olut
ions
.Some pr
obl
ems
,suc
h asbal
anc
ing a c
hec
kbookor
baki
ngac
ake,c
anbes
olved wi
thas
eri
esofac
ti
ons
.Thes
e
s
olut
ionsar
ecal
l
edal
gor
it
hmi
csol
uti
ons
.Onc
etheal
ter
nat
ives

10
havebeenel
i
minat
ed,
forex
ampl
e,andonc
eonehasc
hos
ent
he
bes
tamongs
ever
almet
hodsofbal
anc
ingt
hec
hec
kbook,t
he
s
olut
ionc
anber
eac
hedbyc
ompl
eti
ngt
heac
ti
onsi
nst
eps
.Thes
e
s
teps ar
e c
all
ed t
he al
gor
it
hm.
Whi
l
e an al
gor
it
hm guar
ant
eesan ac
cur
ate ans
wer
,iti
snot
al
way
sthebes
tappr
oac
htopr
obl
ems
olvi
ng.Thi
sst
rat
egyi
snot
pr
act
ic
alf
ormanys
ituat
ionsbec
aus
eitc
anbes
oti
me-
cons
umi
ng.
Forex
ampl
e,i
fyouwer
etr
yingt
ofi
gur
eoutal
loft
hepos
sibl
e
numberc
ombi
nat
ionst
oal
ockus
inganal
gor
it
hm,
itwoul
dtakea
ver
ylongt
ime.

2.
1.2Heur
ist
ics:Thes
olut
iont
osomepr
obl
ems
,suc
hashow t
o
buyt
hebes
tst
ockorwhet
hert
oex
pandt
hec
ompany
,ar
enots
o
s
trai
ght
for
war
d.Thes
esol
uti
ons r
equi
rer
eas
oni
ng bui
l
t on
knowl
edge and ex
per
ienc
e.Sol
uti
onst
hatc
annotbe r
eac
hed
t
hroughadi
rec
tsetofs
tepsar
ecal
l
edheur
ist
ics
olut
ions
.

Heur
ist
ici
saGr
eekwor
dthatmeans‘
fi
nd’
.Inc
omput
ing,t
his
r
efer
sto ex
per
ienc
e-bas
ed t
echni
ques f
or pr
obl
em s
olvi
ng,
l
ear
ning and di
scover
ythat gi
ve a s
olut
ion whi
chi
s not
guar
ant
eedt
obeopt
imal
.Heur
ist
icmet
hodsar
eus
edt
ospeed
up t
he pr
oces
s off
indi
ng a s
ati
sfac
tor
ysol
uti
on vi
a ment
al
s
hor
tcut
sto eas
ethe c
ogni
ti
ve l
oad ofmaki
ng a dec
isi
on.
Ex
ampl
esoft
hismet
hod i
ncl
ude:r
uleoft
humb (
aroughand
pr
act
ic
alappr
oac
h,bas
edonex
per
ienc
e,r
athert
hanas
cient
if
ic
),
11
educ
atedgues
s,ani
ntui
ti
vej
udgment
,orc
ommons
ens
e.Unl
i
ke
al
gor
it
hms
,heur
ist
ic
sdonotal
way
sguar
ant
eeac
orr
ects
olut
ion.
However
,us
ingt
hispr
obl
em-
sol
vi
ngs
trat
egydoesal
l
ow peopl
e
t
osi
mpl
i
fyc
ompl
expr
obl
emsand r
educ
ethet
otalnumberof
pos
sibl
esol
uti
onst
oamor
emanageabl
eset
.

2.
1.3Tr
ial
-
and-
Err
or:
Atr
ial
-
and-
err
orappr
oac
htopr
obl
em-
sol
vi
ng
i
nvol
vest
ryi
ng anumberofdi
ff
erents
olut
ionsand r
uli
ng out
t
hos
ethatdonotwor
k.Thi
sappr
oac
hcanbeagoodopt
ioni
f
y
ouhaveaver
yli
mit
ednumberofopt
ionsavai
l
abl
e.I
fther
ear
e
manydi
ff
erentc
hoi
ces
,youar
ebet
terof
fnar
rowi
ngdownt
he
pos
sibl
eopt
ionsus
inganot
herpr
obl
em-
sol
vi
ngt
echni
quebef
ore
at
tempt
ingt
ri
al
-and-
err
or.

2.
1.4I
nsi
ght
:Ins
omec
ases
,thes
olut
iont
oapr
obl
emc
anappear
asas
uddeni
nsi
ght
.Ac
cor
dingt
ores
ear
cher
s,i
nsi
ghtc
anoc
cur
bec
aus
eyou r
eal
i
zet
hatt
he pr
obl
em i
s ac
tual
l
ysi
mil
art
o
s
omet
hingt
haty
ouhavedeal
twi
thi
nthepas
t,buti
nmos
tcas
es
t
he under
ly
ing ment
alpr
oces
sest
hatl
ead t
oins
ighthappen
out
sideofawar
enes
s

2.
2Pr
obl
ems,
Sol
uti
ons,
andTool
s

Ihaveapr
obl
em!Ineed t
othankAuntKayf
ort
hebi
rt
hday
pr
esents
hes
entme.Ic
oul
dsendat
hanky
ounot
ethr
ought
he
mai
l
.Ic
oul
dcal
lheront
het
elephone.Ic
oul
dsendheranemai
l
12
mes
sage.Ic
oul
ddr
ivet
oherhous
eandt
hankheri
nper
son.I
n
f
act
,ther
ear
emanyway
sIc
oul
dthankher
,butt
hat
'snott
he
poi
nt.Thepoi
nti
sthatImus
tdec
idehow Iwantt
osol
vet
he
pr
obl
em,
andus
etheappr
opr
iat
etool
toi
mpl
ement(
car
ryout
)my
pl
an.The pos
tals
ervi
ce,t
he t
elephone,t
he i
nter
net
,and my
aut
omobi
l
ear
etool
sthatIc
anus
e,butnoneoft
hes
eac
tual
l
y
s
olvesmypr
obl
em.I
nas
imi
l
arway
,ac
omput
erdoesnots
olve
pr
obl
ems
,it
'sj
ustat
oolt
hatIc
anus
etoi
mpl
ementmypl
anf
or
s
olvi
ngt
hepr
obl
em.

Knowi
ngt
hatAuntKayappr
eci
atesc
reat
iveandunus
ual
thi
ngs
,I
havedec
idedt
ohi
reas
ingi
ngmes
sengert
odel
i
vermyt
hanks
.In
t
hisc
ont
ext
,the mes
sengeri
sa t
ool
,butone t
hatneeds
i
nst
ruc
ti
onsf
romme.I
havet
otel
lt
hemes
sengerwher
eAuntKay
l
i
ves
,whatt
imeIwoul
dli
ket
hemes
saget
obedel
i
ver
ed,and
whatl
yr
ic
sIwants
ung.A c
omput
erpr
ogr
am i
ssi
mil
art
o my
i
nst
ruc
ti
onst
othemes
senger
.

Thes
tor
yofAuntKayus
esaf
ami
l
iarc
ont
extt
osett
hes
tagef
or
a us
efulpoi
ntofvi
ew c
onc
erni
ng c
omput
ers and c
omput
er
pr
ogr
ams
.Thef
oll
owi
ngl
i
sts
ummar
izest
hekeyas
pec
tsoft
his
poi
ntofvi
ew.

 Ac
omput
eri
sat
ool
thatc
anbeus
edt
oimpl
ementapl
anf
or
s
olvi
ngapr
obl
em.

13
 Ac
omput
erpr
ogr
am i
sas
etofi
nst
ruc
ti
onsf
orac
omput
er.
Thes
eins
truc
ti
onsdes
cri
bet
hes
tepst
hatt
hec
omput
ermus
t
f
oll
owt
oimpl
ementapl
an.

 Anal
gor
it
hmi
sapl
anf
ors
olvi
ngapr
obl
em.

 Aper
sonmus
tdes
ignanal
gor
it
hm.

 A per
son mus
ttr
ans
lat
e an al
gor
it
hm i
ntoac
omput
er
pr
ogr
am.

Thi
spoi
ntofvi
ews
etst
hes
tagef
orapr
oces
sthatwewi
l
lus
eto
devel
op s
olut
ions t
o Jer
oo pr
obl
ems
.The bas
ic pr
oces
sis
i
mpor
tantbec
aus
eitc
anbeus
ed t
osol
veawi
devar
iet
yof
pr
obl
ems
,inc
ludi
ngoneswher
ethes
olut
ionwi
l
lbewr
it
teni
nsome
ot
herpr
ogr
ammi
ngl
anguage.

14
Chapt
erThr
ee(
3)Conc
ept
sandPr
oper
ti
esofAl
gor
it
hm

3.
1Or
igi
noft
hewor
d“Al
gor
it
hm”

Thewor
d al
gor
it
hm c
omesf
rom t
henameoft
he9t
hcent
ury
Per
sian

Mus
li
m mat
hemat
ic
ian Abu Abdul
l
ah Muhammad i
bn Mus
a Al
-
Khwar
izmi
.Thewor
dal
gor
ism or
igi
nal
l
yref
err
edonl
ytot
her
ules
ofper
for
mingar
it
hmet
icus
ingHi
ndu-
Arabi
cnumer
alsbutevol
ved
vi
a Eur
opean Lat
int
rans
lat
ion of Al
-
Khwar
izmi
'
s name i
nto
al
gor
it
hm byt
he1
8thc
ent
ury
.Theus
eoft
hewor
devol
vedt
o
i
ncl
udeal
ldef
ini
tepr
ocedur
esf
ors
olvi
ngpr
obl
emsorper
for
ming
t
asks
.

3.
2Def
ini
ti
onofanAl
gor
it
hms:

Anal
gor
it
hmi
sanor
der
eds
etofunambi
guous
,ex
ecut
abl
est
eps
t
hatdef
inesat
ermi
nat
ingpr
oces
s.Anal
gor
it
hmi
sas
tep-
by-
step
pr
ocedur
e t
hat wi
l
lal
way
s pr
oduc
e a c
orr
ects
olut
ion. A
mat
hemat
ic
alf
ormul
aisagood ex
ampl
eofapr
obl
em-
sol
vi
ng
al
gor
it
hm.Whi
l
eanal
gor
it
hmguar
ant
eesanac
cur
ateans
wer
,iti
s
notal
way
sthebes
tappr
oac
htopr
obl
ems
olvi
ng.Thi
sst
rat
egyi
s
15
notpr
act
ic
alf
ormanys
ituat
ionsbec
aus
eitc
an be s
oti
me-
c
ons
umi
ng.Forex
ampl
e,i
fyouwer
etr
yingt
ofi
gur
eoutal
loft
he
pos
sibl
enumberc
ombi
nat
ionst
o al
ockus
ing anal
gor
it
hm,i
t
woul
dtakeaver
ylongt
ime.

Ar
epr
esent
ati
onofanal
gor
it
hm i
scal
l
edapr
ogr
am.Fort
he
c
onveni
enc
eofhumans
,comput
erpr
ogr
amsar
eus
ual
l
ypr
int
ed
onpaperordi
spl
ayedonc
omput
ers
creens
.Fort
hec
onveni
enc
e
ofmac
hines
,pr
ogr
amsar
eenc
odedi
namannerc
ompat
ibl
ewi
th
t
he t
echnol
ogyoft
he mac
hine.The pr
oces
sofdevel
opi
ng a
pr
ogr
am,enc
odi
ngi
tinmac
hine-
compat
ibl
efor
m,andi
nser
ti
ngi
t
i
nto a mac
hine i
scal
l
ed pr
ogr
ammi
ng.Pr
ogr
ams
,and t
he
al
gor
it
hmst
heyr
epr
esent
,ar
ecol
l
ect
ivel
yref
err
edt
oassof
twar
e,
i
ncont
rastt
othemac
hiner
yit
sel
f,
whi
chi
sknownashar
dwar
e.

3.
3Pr
oper
ti
esofAl
gor
it
hm:
-

I
ti
swr
it
teni
nsi
mpl
eEngl
i
sh.

 Eac
hst
epofanal
gor
it
hmi
suni
queands
houl
dbes
elf
ex
planat
ory
.

 Anal
gor
it
hmmus
thaveatl
eas
tonei
nput
.

 Anal
gor
it
hmmus
thaveatl
eas
toneout
put
.

 Anal
gor
it
hmhasf
ini
tenumberofs
teps
.

16
I
tshoul
dpr
ovi
det
hec
orr
ects
olut
ions

 Shoul
dhaveanendpoi
nt

3.
4Benef
it
sOfUsi
ngAl
gor
it
hmI
nPr
obl
em-
Sol
vi
ng

Apr
obl
emc
anbes
olvedbyus
ingac
omput
eronl
yifanal
gor
it
hm
c
anbewr
it
tenf
ori
t.I
naddi
ti
on,t
heus
eofal
gor
it
hm pr
ovi
des
manyot
herbenef
it
s:-
• Whi
l
e wr
it
ing an al
gor
it
hm,y
ou i
dent
if
ythe s
tep-
by-
step
pr
ocedur
e,t
hemaj
ordec
isi
onpoi
nts
,andt
hevar
iabl
esnec
ess
ary
t
osol
vet
hepr
obl
em.Thi
shel
psy
oui
nthedevel
opmentoft
he
c
orr
espondi
ngpr
ogr
am.
•I
dent
if
ic
ati
onoft
hepr
ocedur
eandt
hedec
isi
onpoi
ntsr
educ
es
t
he pr
obl
em i
nto a s
eri
es of s
mal
l
er pr
obl
ems of mor
e
manageabl
esi
ze.Ther
efor
e,pr
obl
emst
hatwoul
dbedi
ff
ic
ultor
i
mpos
sibl
etos
olveasawhol
ecanbeappr
oac
hedasas
eri
esof
s
mal
lsol
vabl
esubpr
obl
ems
.
•Wi
tht
heus
eofanal
gor
it
hm,dec
isi
onmaki
ngbec
omesamor
e
r
ati
onal
proc
ess
.Thi
sisbec
aus
eal
gor
it
hmsc
ompr
iseofs
ubt
asks
,
wher
eeac
hsubt
aski
sat
omi
cinnat
ureandi
ssuppor
tedbyf
act
s.
•Wi
tht
heus
eofanal
gor
it
hm,
thes
ames
pec
if
ieds
tepsar
eus
ed
f
orper
for
mingt
het
asks
.Thi
smakest
hepr
oces
smor
econs
ist
ent
andr
eli
abl
e.
3.
5Devel
opmentPr
ocessesofAnAl
gor
it
hm

17
Ther
e ar
e manyway
sto wr
it
e an al
gor
it
hm.Some ar
e ver
y
i
nfor
mal
,somear
equi
tef
ormalandmat
hemat
ic
ali
nnat
ure,and
s
omear
equi
tegr
aphi
cal
.Thei
nst
ruc
ti
onsf
orc
onnec
ti
ngaDVD
pl
ayert
oat
elevi
si
onar
eanal
gor
it
hm.Amat
hemat
ic
alf
ormul
a
s
uchasπR2i
sas
pec
ialc
aseofanal
gor
it
hm.Thef
ormi
snot
par
ti
cul
arl
yimpor
tantasl
ong asi
tpr
ovi
desa good wayt
o
des
cri
beandc
hec
kthel
ogi
coft
hepl
an.

Thedevel
opmentofanal
gor
it
hm (
apl
an)i
sakeys
tepi
nsol
vi
ng
apr
obl
em.Onc
ewehaveanal
gor
it
hm,wec
ant
rans
lat
eiti
ntoa
c
omput
erpr
ogr
ami
nsomepr
ogr
ammi
ngl
anguage.Oural
gor
it
hm
devel
opmentpr
oces
scons
ist
soff
ivemaj
ors
teps
.

St
ep1:
Obt
ainades
cri
pti
onoft
hepr
obl
em.

St
ep2:
Anal
yzet
hepr
obl
em.

St
ep3:
Devel
opahi
gh-
l
evel
algor
it
hm.

St
ep4:
Ref
inet
heal
gor
it
hmbyaddi
ngmor
edet
ail
.

St
ep5:
Revi
ewt
heal
gor
it
hm.

St
ep1:Obt
ainaDesc
ri
pti
onoft
hePr
obl
em.

Thi
sst
epi
smuc
hmor
edi
ff
ic
ultt
hani
tappear
s.I
nthef
oll
owi
ng
di
scus
sion,
t dc
hewor l
i
entr
efer
stos
omeonewhowant
stof
inda
s
olut
iont
oapr
obl
em,
andt ddevel
hewor operr
efer
stos
omeone
whof
indsawayt
osol
vet
hepr
obl
em.Thedevel
opermus
tcr
eat
e

18
anal
gor
it
hmt
hatwi
l
lsol
vet
hec
li
ent
'spr
obl
em.

Thec
li
enti
sres
pons
ibl
eforc
reat
ingades
cri
pti
onoft
hepr
obl
em,
butt
hisi
sof
ten t
he weakes
tpar
toft
he pr
oces
s.I
t'
squi
te
c
ommonf
orapr
obl
em des
cri
pti
ont
osuf
ferf
rom oneormor
eof
t
he f
oll
owi
ng t
ypes ofdef
ect
s:(
1)t
he des
cri
pti
on r
eli
es on
uns
tat
edas
sumpt
ions
,(2)t
hedes
cri
pti
oni
sambi
guous
,(3
)the
des
cri
pti
on i
sinc
ompl
ete,or(
4)t
he des
cri
pti
on has i
nter
nal
c
ont
radi
ct
ions
.Thes
edef
ect
sar
esel
dom (
occ
asi
onal
l
y)duet
o
c
arel
ess
nes
sbyt
hec
li
ent
.Ins
tead,t
heyar
eduet
othef
actt
hat
nat
urall
anguages (
Engl
i
sh,Fr
enc
h,Kor
ean,et
c.)ar
erat
her
i
mpr
eci
se(
inac
cur
ate)
.Par
toft
hedevel
oper
'sr
espons
ibi
l
it
yist
o
i
dent
if
ydef
ect
sint
hedes
cri
pti
onofapr
obl
em,andt
owor
kwi
th
t
hec
li
entt
oremedyt
hos
edef
ect
s.

St
ep2:Anal
yzet
hepr
obl
em.

Thepur
pos
eoft
hiss
tepi
stodet
ermi
nebot
hthes
tar
ti
ngand
endi
ngpoi
ntsf
ors
olvi
ngt
hepr
obl
em.Thi
spr
oces
sisanal
ogous
(
si
mil
ar)t
oamat
hemat
ic
iandet
ermi
ni
ngwhati
sgi
venandwhat
mus
tbepr
oven.Agoodpr
obl
em des
cri
pti
onmakesi
teas
iert
o
per
for
mthi
sst
ep.

Whendet
ermi
ni
ngt
hes
tar
ti
ngpoi
nt,wes
houl
dst
artbys
eeki
ng
ans
wer
stot
hef
oll
owi
ngques
tions
:

19
 Whatdat
aar
eavai
l
abl
e?

 Wher
eist
hatdat
a?

 Whatf
ormul
asper
tai
ntot
hepr
obl
em?

 Whatr
ulesex
istf
orwor
kingwi
tht
hedat
a?

 Whatr
elat
ions
hipsex
istamongt
hedat
aval
ues
?

Whendet
ermi
ni
ng t
heendi
ng poi
nt,weneed t
o des
cri
bet
he
c
har
act
eri
sti
csofas
olut
ion.I
not
herwor
ds,how wi
l
lweknow
whenwe'
redone?As
kingt
hef
oll
owi
ngques
tionsof
tenhel
pst
o
det
ermi
net
heendi
ngpoi
nt.

 Whatnewf
act
swi
l
lwehave?

 Whati
temswi
l
lhavec
hanged?

 Whatc
hangeswi
l
lhavebeenmadet
othos
eit
ems
?

 Whatt
hingswi
l
lnol
ongerex
ist
?

Agoodwayt
oanal
yzeapr
obl
emi
stos
epar
atei
ti
ntof
ourpar
ts:
a.Thegi
vendat
a
b.Ther
equi
redr
esul
ts
c
.Thepr
oces
singt
hati
srequi
redi
nthepr
obl
em
d.Al
i
stofs
olut
ional
ter
nat
ives
Thi
siswel
lr
epr
esent
edi
nthePr
obl
emAnal
ysi
sChar
t.

20
Pr
obl
emAnal
ysi
sChar
t(PAC)

Pr
ogr
ammerc
anus
ethi
sfor
m/c
har
ttos
ortpr
obl
emout
,
 PACal
l
owst
hepr
obl
em s
olvert
oel
i
minat
ethewor
dsand
gl
eanonl
ythef
act
sfr
omt
hepr
obl
em.
 Dat
a,c
ons
tant
sand var
iabl
es,go i
ntot
he Gi
ven Dat
a
s
ect
ion.
 Requi
rement
sfort
he out
putr
epor
ts woul
d be ent
ered
underRequi
redRes
ult
s.
 Anyequat
ionsorot
herpr
oces
singr
equi
rement
swoul
dbe
l
i
stedi
nthePr
oces
singRequi
reds
ect
ion.
 Fi
nal
l
y,t
hepr
ogr
ammerwoul
d wr
it
eanyot
heri
deast
hat
s
pri
ng t
o mi
nd c
onc
erni
ng t
he s
olut
ion i
nthe Sol
uti
on
Al
ter
nat
ivess
ect
ion.
Wes
eeex
ampl
eHERE.
..
 Cons
idera pr
obl
em t
o Cal
cul
atet
he gr
oss pay ofan
empl
oyeegi
vent
hehour
swor
kedandt
her
ateofpay
.
Weknowt
hatt
hegr
osspayi
scal
cul
atedbymul
ti
pl
yi
ngt
hehour
s
21
wor
kedbyt
her
ateofpay
.
i
.
e, Gr
ossPay=Hour
s*PayRat
e
Thus,
usi
ngt
hePAC,
we’
ve:

Pr
obl
emAnal
ysi
sChar
tfort
hePay
rol
lPr
obl
em

1.Def
inet
hehour
swor
kedandt
hepayr
ateasc
onstant
s.
2.Def
inet
hehour
swor
kedandt
hepayr
ateasi
nputval
ues

Thesecondalter
nativewi
l
lbeused, ass
ignif
iedbytheast
eri
ski
n
thefi
gure,
sinc
et heprogr
amwill
notneedt obec hangedi
norder
tocal
cul
atethegr os
spayforanotheremployee.

Thepr obl
emanal ys
isc
harti
sanaidt ocl
earthi
nking
becauseithelpstheprobl
ems ol
vert
oidentif
ytheessentialdata
andinformati
oninapr obl
emandt odi
sregardthenones senti
al
s.
Mos tprobl
emspr ogrammersworkwit
har ewordproblems .Thi
s
i
struewhet hertheyareworki
nginacl
as s
rooms i
tuati
onorouton
thejob.ThePAChel pstoparedownthewor ds.

Pr
obl
em:Mar
ySmi
thi
slooki
ngf
ort
hebankt
hatwi
l
lgi
vet
he
mos
tret
urnonhermoneyovert
henex
tfi
vey
ear
s.Shehas
22
$2
,000t
oputi
ntoas
avi
ngsac
count
.Thes
tandar
dequat
iont
o
c
alc
ulat
epr
inc
ipal
plusi
nter
estatt
heendofaper
iodoft
imei
s
Amount=P*
(1+I
/M)
^(N*M)
wher
e:
P=Pr
inc
ipal
(amountofmoneyt
oinves
t,i
nthi
scas
e$2,
000)
I=I
nter
est(
per
cent
ager
atet
hebankpay
stot
hei
nves
tor
)
N=NumberofYear
s(t
imef
orwhi
cht
hepr
inc
ipal
isi
nves
ted)
M =CompoundI
nter
val
(thenumberoft
imespery
eart
hei
nter
est
i
scal
cul
atedandaddedt
othepr
inc
ipal
)
 PAC ai
dst
ocl
eart
hinki
ng bec
aus
eithel
pst
he pr
obl
em
s
olveri
dent
if
ythe es
sent
ialdat
a and i
nfor
mat
ion i
na
pr
obl
emandt
odi
sregar
dthenones
sent
ial
s.
 Mos
tpr
obl
ems t
hatpr
ogr
ammer
s wor
k wi
th ar
e wor
d
pr
obl
ems
.Thi
sist
rue whet
hert
hey ar
e wor
king i
na
c
las
srooms
ituat
ionoroutont
hej
ob.

St
ep3:Devel
opahi
gh-
l
evel
algor
it
hm.

Anal
gor
it
hmi
sapl
anf
ors
olvi
ngapr
obl
em,
butpl
ansc
omei
n
s
ever
all
evel
sofdet
ail
.I
t'
sus
ual
l
ybet
tert
ost
artwi
thahi
gh-
l
evel
algor
it
hmt
hati
ncl
udest
hemaj
orpar
tofas
olut
ion,
but
l
eavest
hedet
ail
sunt
il
lat
er.Wec
anus
eanever
ydayex
ampl
e
t
odemons
trat
eahi
gh-
l
evel
algor
it
hm.

Pr
obl
em:I
needt
osendabi
rt
hdayc
ardt
omybr
other
,Mar
k.

23
Anal
ysi
s'don'
thaveac
ard.I
pref
ert
obuyac
ardr
athert
han
makeonemy sel
f.

Hi
gh-
l
evel
algor
it
hm:

Got
oas
tor
ethats
ell
sgr
eet
ingc
ards
Sel
ectac
ard
Pur
chas
eac
ard
Mai
lt
hec
ard

Thi
sal
gor
it
hm i
ssat
isf
act
oryf
ordai
l
yus
e,buti
tlac
ksdet
ail
sthat
woul
d have t
o be added wer
eac
omput
ert
ocar
ryoutt
he
s
olut
ion.Thes
edet
ail
sinc
ludeans
wer
stoques
tionss
uchast
he
f
oll
owi
ng.

 "
Whi
chs
tor
ewi
l
lIvi
si
t?"

 "
Howwi
l
lIgett
her
e:wal
k,dr
ive,
ri
demybi
cyc
le,
taket
he
bus?"

 "
WhatkindofcarddoesMarkli
ke:humor
ous
(funny
),
s
entiment
al(emoti
onal
),
ri
squé(
naughty)
?"

Thes
eki
ndsofdet
ail
sar
econs
ider
edi
nthenex
tst
epofour
pr
oces
s.St
ep4:Ref
inet
heal
gor
it
hmbyaddi
ngmor
edet
ail
.
Ahi
gh-
l
evel
algor
it
hms
howst
hemaj
ors
tepst
hatneedt
obe
f
oll
owedt
osol
veapr
obl
em.Nowweneedt
oadddet
ail
stot
hes
e
s
teps
,buthowmuc
hdet
ail
shoul
dweadd?Unf
ort
unat
ely
,the
24
ans
wert
othi
sques
tiondependsont
hes
ituat
ion.Wehavet
o
c
ons
iderwho(
orwhat
)isgoi
ngt
oimpl
ementt
heal
gor
it
hmand
howmuc
hthatper
son(
ort
hing)al
readyknowshowt
odo.I
f
s
omeonei
sgoi
ngt
opur
chas
eMar
k'sbi
rt
hdayc
ardonmybehal
f,
myi
nst
ruc
ti
onshavet
obeadapt
edt
owhet
herornott
hat
per
soni
sfami
l
iarwi
tht
hes
tor
esi
nthec
ommuni
tyandhowwel
l
t
hepur
chas
erknownmybr
other
'st
ast
eingr
eet
ingc
ards
.

Whenourgoal
ist
odevel
opal
gor
it
hmst
hatwi
l
ll
eadt
ocomput
er
pr
ogr
ams
,weneedt
ocons
idert
hec
apabi
l
it
iesoft
hec
omput
er
andpr
ovi
deenoughdet
ails
othats
omeoneel
sec
oul
dus
eour
al
gor
it
hm t
owr
it
eac
omput
erpr
ogr
am t
hatf
oll
owst
hes
tepsi
n
oural
gor
it
hm.Aswi
tht
hebi
rt
hdayc
ardpr
obl
em,weneed t
o
adj
ustt
hel
evelofdet
ail
tomat
cht
heabi
l
it
yoft
hepr
ogr
ammer
.
Wheni
ndoubt
,orwheny
ouar
elear
ning,i
tisbet
tert
ohavet
oo
muc
hdet
ail
thant
ohavet
ool
i
ttl
e.

Mos
tofourex
ampl
eswi
l
lmovef
rom ahi
gh-
l
evelt
oadet
ail
ed
al
gor
it
hm i
nas
ingl
est
ep,butt
hisi
snotal
way
sreas
onabl
e.For
l
arger
,mor
ecompl
expr
obl
ems
,iti
scommont
ogot
hrought
his
pr
oces
ssever
alt
imes
,devel
opi
ngi
nter
medi
atel
evelal
gor
it
hms
as we go.Eac
hti
me,we add mor
e det
ailt
othe pr
evi
ous
al
gor
it
hm,
stoppi
ngwhenwes
eenobenef
itt
ofur
therr
efi
nement
.
Thi
stec
hni
queofgr
adual
l
ywor
kingf
romahi
gh-
l
evel
toadet
ail
ed
al
gor
it
hmi
sof
tenc
all
edst
epwi
ser
efi
nement
.
25
St
epwi
se r
efi
nementi
s a pr
oces
sfordevel
opi
ng a det
ail
ed
al
gor
it
hmbygr
adual
l
yaddi
ngdet
ail
toahi
gh-
l
evel
algor
it
hm.

St
ep5:Revi
ewt
heal
gor
it
hm.

Thef
inal
stepi
stor
evi
ewt
heal
gor
it
hm.Whatar
ewel
ooki
ngf
or?
Fi
rst
,weneedt
owor
kthr
ought
heal
gor
it
hm s
tepbys
tept
o
det
ermi
newhet
herornoti
twi
l
lsol
vet
heor
igi
nalpr
obl
em.Onc
e
wear
esat
isf
iedt
hatt
heal
gor
it
hmdoespr
ovi
deas
olut
iont
othe
pr
obl
em,
wes
tar
ttol
ookf
orot
hert
hings
.Thef
oll
owi
ngques
tions
ar
ety
pic
alofonest
hats
houl
dbeas
kedwheneverwer
evi
ewan
al
gor
it
hm.As
kingt
hes
eques
tionsands
eeki
ngt
hei
rans
wer
sisa
good wayt
o devel
op s
kil
l
sthatc
an be appl
i
ed t
othe nex
t
pr
obl
em.

 Doest
hisal
gor
it
hm s
olveaver
yspec
ifi
cpr
obl
em ordoesi
t
s
olve a mor
e gener
alpr
obl
em?I
fits
olvesa ver
yspec
if
ic
pr
obl
em,
shoul
ditbegener
ali
zed?

Forexampl
e,anal
gor
it
hm t
hatc
omput
est
hear
eaofac
ir
cl
e
havi
ngr
adi
us5.
2met
ers(
for
mul
aπ*
5.22)s
olvesaver
yspec
if
ic
pr
obl
em,butanal
gor
it
hm t
hatc
omput
est
hear
eaofanyc
ir
cl
e
(
for
mul R2)s
aπ* olvesamor
egener
alpr
obl
em.

 Cant
hisal
gor
it
hmbesi
mpl
i
fi
ed?

Onef
ormul
aforc
omput
ingt
heper
imet
erofar
ect
angl
eis
:

26
l
engt
h+wi
dth+l
engt
h+wi
dth
As
impl
erf
ormul
awoul
dbe:

2. l
engt
0*( h+wi
dth)
 I
sthi
ssol
uti
onsi
mil
art
othes
olut
iont
oanot
herpr
obl
em?
Howar
etheyal
i
ke?Howar
etheydi
ff
erent
?

Forex
ampl
e,c
ons
idert
hef
oll
owi
ngt
wof
ormul
ae:

Rectangl
earea=lengt
h*width
Tri
anglear 5*bas
ea=0. e*hei
ght
Si
mil
ari
ti
es:Eachc
omput
es an ar
ea.Eac
h mul
ti
pl
ies t
wo
measur
ements.

Dif
fer
ences:Dif
fer
entmeas
urement
sar
eus
ed.Thet
ri
angl
e
for
mulac
ontains0.
5.

Hy
pot
hesi
s:Per
hapsever
yar
eaf
ormul
ainvol
vesmul
ti
pl
yi
ng
t
womeas
urement
s.

Exampl
es1:Wr
it
eanal
gor
it
hmt
odet
ermi
neas
tudent
’sf
inal
gr
adeandi
ndi
cat
ewhet
heri
ti
spas
singorf
ail
i
ng.Thef
inal
grade
i
scal
cul
atedast
heaver
ageoff
ourmar
ks.
Sol
uti
on1:
 Detai
ledAl
gorit
hm
 Step1: I nputM1,M2,M3,
M4
 Step2: GRADE ( M1+M2+M3+M4)
/4
 Step3: i f(GRADE<50)then
Print“FAI
L”
el
se
Print“PASS”
Endi
f

27
Exampl
e2:Wr
it
eanal
gor
it
hmanddr
awaf
lowc
har
ttoc
onver
t
t
hel
engt
hinf
eett
ocent
imet
er.
Sol
uti
on2:

 Detail
edAl
gor
it
hm
 St
ep1:I
nputLft
 St
ep2: Lc
m Lf tx30
 St
ep3: Pr
intLc
m

Ex
ampl
e3:Wr
it
eanal
gor
it
hmanddr
awaf
lowc
har
ttoc
alc
ulat
ethear
eaof
ar
ect
angl
e.

Sol
uti
on3:

 Detai
l
edAl
gorit
hm
 Step1: InputW,L
 Step2: A LxW
 Step3: PrintA

Ex
ampl
e4

Wr
it
eanal
gor
it
hm t
ocal
cul
atet
hes
impl
eint
eres
tus
ingt
he
f
ormul
a.

28
Si
mpl
eint
eres
t=P*
T*R/
100.

Wher
ePi
spr
inc
ipl
eAmount
,Ti
sthenumberofy
ear
sandRi
s
t
her
ateofi
nter
est
.

Sol
uti
on4:

St
ep1
:Readt
het
hreei
nputquant
it
ies
’P,
TandR.

St
ep2:Cal
cul
ates
impl
eint
eres
tas

Si
mpl
eint
eres
t=P*T*R/
100

St
ep3
:Pr
ints
impl
eint
eres
t.

St
ep4
:St
op.

Ex
ampl
e5:

Wr
it
eanal
gor
it
hm t
ofi
ndt
hear
eaoft
het
ri
angl
e.Letb,cbe
t
hes
idesoft
het
ri
angl
eABCandAt
hei
ncl
udedangl
ebet
ween
t
hegi
vens
ides
.

Sol
uti
on5

St
ep1:I
nputt
hegi
venel
ement
soft
het
ri
angl
enamel
ysi
desb,

29
candangl
ebet
weent
hes
idesA.

St
ep2
:Ar
ea=(
1/2)*
b*C*s
inA

St
ep3
:Out
putt
heAr
ea

St
ep4
:St
op.

Chapt
erFour(
4):I
mpl
ement
ati
onsSt
rat
egi
es,

4.
1Impl
ementat
ionsStr
ategies
St
epsofprobl
ems ol
vi
ngusinganAl
gor
it
hm

- For
mul
ateagener
ali
dea
- Ref
inei
ti
ntodet
ail
eds
tepbys
tepmet
hods(
per
haps
us
ingps
eudoc
odeorf
lowc
har
t).
NOTE;anal
gor
it
hmi
sjus
tamet
hodt
haty
ouc
andes
cri
beus
inga
ps
eudoc
ode,f
lowc
har
t,apr
ogr
am oranyot
herwayi
ntel
l
igi
bl
eto
man.

4.
2Pseudoc
ode
Pseudoc
ode i
s an ar
ti
fi
ci
aland i
nfor
mall
anguage t
hathel
ps
pr
ogr
ammer
stodevel
opal
gor
it
hms
.Ps
eudoc
odei
sver
ysi
mil
ar
t
oever
ydayEngl
i
sh.
I
tist
heNat
uralLanguager
epr
esent
ati
onofaPr
ogr
am or
al
gor
it
hm

30
I
t us
es t
he s
truc
tur
alc
onvent
ions of a pr
ogr
ammi
ng
l
anguage,buti
sint
ended f
orhumanr
eadi
ng r
athert
han
mac
hiner
eadi
ng
I
tisus
edt
oex
plai
napr
ogr
am t
osomeonewhomaynot
under
standt
hepar
ti
cul
arpr
ogr
ammi
ngl
anguagei
nwhi
chi
t
wasmade
 Ps
eudoc
ode gener
all
ydoesnotac
tual
l
yobeyt
he s
ynt
ax
r
ules ofany par
ti
cul
arl
anguage,t
her
eis no s
yst
emat
ic
s
tandar
dfor
m,al
thoughanypar
ti
cul
arwr
it
erwi
l
lgener
all
y
bor
row s
tyl
e and s
ynt
ax.Popul
ars
ynt
axs
our
cesi
ncl
ude
Pas
cal
,BASI
C,C,
C++,
Java,
andALGOL
Af
ewr
ulesgover
ningps
eudoc
odear
e:
- Var
iabl
edec
lar
ati
onsmos
tlyomi
tt
ed.
- Func
ti
onc
all
sandbl
ocksofc
ode,s
uchasc
odec
ont
ained
wi
thi
nal
oop,ar
eof
tenr
epl
aced byaone-
l
inenat
ural
l
anguages
ent
enc
e.
- Showkeywor
dsi
ncapi
tal
let
ter
seg.I
F,ENDI
F,DO,
ENDDO,
THENet
c.
- Punc
tuat
ioni
sopt
ional
- Ever
yIFmus
tendwi
thanENDI
F.
4.
2.1Advant
agesofusi
ngpseudoc
ode
I
tbr
idgest
he gap bet
ween human and c
omput
er
l
anguages

31
I
tisani
mmedi
atenot
ati
ont
hatal
l
owsex
pres
sionof
pr
ogr
am l
ogi
cins
trai
ghtf
orwar
d,eas
ytounder
stand
mannerwi
thoutc
onc
erni
ngt
hepr
ogr
ammerwi
ths
ynt
ax
det
ail
s.
I
tiseas
iert
omakec
hangest
ops
eudoc
odet
hant
oa
s
our
cepr
ogr
ami
nahi
ghl
evel
language.
I
tal
l
owsf
ors
truc
tur
edwal
k-
thr
ough
Exampl
es1:Wr
it
eaps
eudoc
odet
odet
ermi
neas
tudent
’sf
inal
gr
adeandi
ndi
cat
ewhet
heri
ti
spas
singorf
ail
i
ng.Thef
inal
grade
i
scal
cul
atedast
heaver
ageoff
ourmar
ks
Pseudocode
 Inputasetof4mar
ks
 Cal
cul
atet
hei
raver
agebysummi
nganddi
vi
di
ngby4

 i
faver
agei
sbel
ow50
Exampl
e2:Wr
it
eaps
e
Pr
iud
nt“
Fo
Ac
I
Lo
”det
oconver
tthel
engt
hinf
eett
o
c
ent
imet
er. el
se
Pr
int“
PASS”
Sol
uti
on2:
Pseudocode
 Inputthelengt
hinfeet(
Lft
)
 Calcul
atet hel
engt
hincm(Lcm)bymul
ti
pl
yi
ng
LFTwith30
 Pr i
ntl
engthincm(LCM)

Ex
ampl
e3:Wr
ieaps
t eudoc
odet
ocal
cul
atet
hear
eaofar
ect
angl
e.

Sol
uti
on3:
Pseudocode
 Inputthewidt
h(W)andLength(L)ofar
ect
angl
e
 Calcul
atethearea(
A)bymult
ipl
yingLwi
thW
 Pr i
ntA
32
4.
3Pr
ogr
amFl
owChar
t
Pr
ogr
am Fl
owChar
tisagr
aphi
cal
repr
esent
ati
onoft
hepr
ogr
am
l
ogi
cins
olvi
ng a pr
obl
em.I
tus
es t
he s
tandar
dsy
mbol
sin
des
igni
ngt
hei
nput
,pr
oces
sandout
putofapr
ogr
am.Pr
ogr
am
f
lowc
har
tss
howt
hes
equenc
eofi
nst
ruc
ti
onsi
nas
ingl
epr
ogr
am
ors
ubr
out
ine.Di
ff
erents
ymbol
sar
eus
edt
odr
aw eac
hty
peof
f
lowc
har
t.St
epsar
edes
cri
bedi
nbox
esofvar
iouski
nds
,and
t
hei
ror
deri
ndi
cat
edbyc
onnec
ti
ngt
hem wi
thar
rows
.Fl
owc
har
ts
ar
e us
ed i
nanal
yzi
ng,des
igni
ng,doc
ument
ing ormanagi
ng a
pr
oces
sorpr
ogr
am.
4.
3.1Sy
mbol
susedi
nPr
ogr
amFl
owChar
t
Thet
abl
ebel
ows
howst
hes
ymbol
sus
edi
ndr
awi
ngt
hePr
ogr
am
Fl
ow
Char
t.

33
4.
3.2Thr
eePr
ogr
amConst
ruc
tsi
nPr
ogr
amFl
owChar
t
Al
lpr
ogr
am des
igns c
an be c
ons
truc
ted us
ing t
hree bas
ic
c
ons
truc
ts.I
ti
sal
sot
hec
onc
eptofs
truc
tur
edpr
ogr
ammi
ngt
hata
pr
ogr
am s
houl
dbedevel
opedus
ingt
het
hreebas
icc
ons
truc
ts.
Thet
hreebas
icc
ons
truc
tsi
npr
ogr
ammi
ngar
e:
s
equenc
e
s
elec
ti
on
i
ter
ati
on
Whendes
igni
ngt
hepr
ogr
am,
wear
eal
soabl
etor
epr
esentt
he

34
t
hreebas
icc
ons
truc
tsus
ingt
hePr
ogr
amFl
owChar
t.
4.
3.2.
1Sequenc
e
I
nas
equenc
econs
truc
t,eac
hins
truc
ti
oni
sex
ecut
edi
nas
eri
al
manner
,oneaf
teranot
her
.Forex
ampl
e,apr
ogr
am r
equi
rest
he
us
ert
oent
ert
wonumber
snum1andnum2.Thepr
ogr
am t
hen
c
alc
ulat
est
heans
werbydi
vi
di
ngnum1bynum2,anddi
spl
ayst
he
r
esul
tbef
orei
tter
minat
es.Thedi
agr
am bel
ows
howst
hedes
ign
oft
hepr
ogr
amus
ingt
hef
lowc
har
t.

4.
3.2.
2Sel
ect
ion
Thes
elec
ti
onc
ons
truc
tpr
ovi
desadec
isi
onpoi
ntt
hatal
l
owsone
oft
het
woc
hoi
cest
obec
hos
enbas
edons
omeval
uewi
thi
na
pr
ogr
am.Forex
ampl
e,apr
ogr
am r
equi
rest
heus
ert
oent
ert
wo
number
snum1andnum2
.Ift
hes
econdnumberent
eredi
szer
o,
t
he pr
ogr
am wi
l
ldi
spl
aya mes
sage “
divi
si
on byz
ero er
ror
”,
ot
her
wis
eitwi
l
lcal
cul
atet
heans
werbydi
vi
di
ngnum1bynum2.
Thepr
ogr
am t
hendi
spl
ayst
her
esul
tbef
orei
tter
minat
es.The
35
di
agr
am bel
owi
saf
lowc
har
trepr
esent
ati
onoft
hedes
ignoft
he
pr
ogr
am.

Anot
herex
ampl
e,i
fapr
ogr
ami
samenudr
ivenpr
ogr
am,
ital
l
ows
t
heus
ert
omakeac
hoi
ce.I
ftheus
ers
elec
tst
hef
ir
stopt
ion,i
t
di
spl
ays a mes
sage “
opt
ion one s
elec
ted”
.Ifopt
ion t
wo i
s
s
elec
ted,i
tdi
spl
aysames
sage“
opt
iont
wos
elec
ted”andi
fus
er
s
elec
tsopt
iont
hree,
itdi
spl
aysames
sage“
opt
iont
hrees
elec
ted”
.
Las
tly
,ift
heus
erent
eredawr
ongopt
ion,ames
sage“
inval
i
d
opt
ion”wi
l
lbedi
spl
ayed.Thedi
agr
ambel
ows
howst
hedes
ignof
t
hispr
ogr
amus
ingt
hef
lowc
har
t.

36
4.
3.2.
3It
erat
ion
Thei
ter
ati
onc
ons
truc
tal
l
owsas
etofi
nst
ruc
ti
onst
ober
epeat
ed
anumberoft
imesbas
edont
hec
ondi
ti
ons
tat
ed.Thel
oopwi
l
l
endwhent
hec
ondi
ti
onhasbeenf
ulf
il
l
ed.Forex
ampl
e,apr
ogr
am
i
ni
ti
al
iz
est
heval
ueofvar
iabl
e‘t
otal
’toz
ero.I
tthenr
equi
rest
he
us
ert
oent
eranumber
.Ift
henumbert
hatwasent
eredi
sles
s
t
han10
00,i
twi
l
laddt
henumbert
othet
otal
andas
kforanot
her
numbert
o be ent
ered.Onl
ywhent
he us
erent
ersa number
gr
eat
ert
han1000,t
hepr
ogr
am wi
l
lthendi
spl
ayt
het
otalt
hati
s
37
ac
cumul
atedbef
oret
hepr
ogr
am t
ermi
nat
es.Thedi
agr
am bel
ow
i
l
l
ust
rat
est
hedes
ignoft
hepr
ogr
amus
ingt
hef
lowc
har
t.

Pr
ogr
ammi
ngExer
cises
1.Nameany4s
ymbol
sus
edi
nfl
owc
har
t.
2.Us
ethe f
lowc
har
ttos
how t
he t
hree pr
ogr
am c
ons
truc
t:
s
equenc
e,s
elec
ti
onandi
ter
ati
on.
3.Connec
tor
sar
eus
eds
omet
imesi
ndr
awi
ngaf
lowc
har
t.Ex
plai
n
whens
houl
dac
onnec
torbeus
ed.

38
Pr
ogr
amf
lowc
har
tforExampl
es1above

Pr
ogr
amf
lowc
har
tforExampl
e2above

39
Pr
ogr
amf
lowc
har
tforExampl
e3above

4.
4Pr
ogr
amFl
owCont
rol
4.
4.1Sel
ect
ionSt
atement
s
I
nthepr
evi
ousc
hapt
er,wehavel
ear
nedhowt
owr
it
epr
ogr
ams
t
hatc
anac
cepti
nput
s,wec
ant
her
efor
e,al
tert
heevent
sthat
oc
curwi
thi
nthe pr
ogr
am bas
ed on t
he us
er’
sinputal
l
owi
ng
dec
isi
onmaki
ngt
otakepl
ace.Tomakeadec
isi
on,i
tinvol
ves
c
hoos
ingbet
weent
woal
ter
nat
ivec
our
sesofac
ti
onbas
eds
ome
val
uewi
thi
napr
ogr
am.

40
Sel
ect
ions
tat
emental
l
owsourpr
ogr
amt
ochoos
edi
ff
erentpat
hs
ofex
ecut
ionbas
edont
heout
comeofanex
pres
sionort
hes
tat
e
oft
hevar
iabl
e.Theex
pres
sionorval
ueuponwhi
chadec
isi
oni
s
madei
sal
way
saBool
eanval
ue,whi
chi
sal
way
soneoft
wo
val
ues– t
rue orf
als
e.Java s
uppor
tst
wo ki
ndsofs
elec
ti
on
s
tat
ement
s:i
fori
f.
.el
ses
tat
ementandt
hes
wit
chs
tat
ement
.
4.
4.1.
1Thei
fst
ruc
tur
e
As
ingl
eifs
tat
ementi
ssomet
imesc
all
ed a s
ingl
e-al
ter
nat
eif
bec
aus
eweonl
yper
for
manac
ti
onbas
edononeal
ter
nat
ive.

synt
ax:
i
f(c
ondi
ti
on)
s
tat
ement;/
/ex
ecut
edwhenc
ondi
ti
oni
str
ue
Exampl
e
i
f(ans
wer==‘
C’)
Sy
stem.
out
.pr
int
ln(
“Youc
hoos
etoc
ont
inue.
”)
;
I
f(ans
wer==‘
Q’)
Sy
stem.
out
.pr
int
ln(
“Youc
hoos
etoqui
t.
”)
;
4.
4.1.
2Thei
f.
.el
sest
ruc
tur
e
Thei
f.
.el
ses
tat
ementi
scal
l
edadual
-
alt
ernat
eif
,whi
chr
equi
res
t
wo opt
ions f
ort
he nex
tcour
se ofac
ti
on.I
tpr
ovi
des t
he
mec
hani
smt
oper
for
m oneac
ti
onwhenaBool
eanex
pres
sion
eval
uat
esast
rueandper
for
msanot
herac
ti
onwhent
heBool
ean
ex
pres
sioneval
uat
esasf
als
e.

41
synt
ax:
i
f(c
ondi
ti
on)
s
tat
ement1;/
/ex
ecut
edwhenc
ondi
ti
oni
str
ue
el
se
s
tat
ement2;/
/ex
ecut
edwhenc
ondi
ti
oni
sfal
se
Exampl
e
i
f(age>=21)
Sy
stem.
out
.pr
int
ln(
“Youar
eanadul
t”
);
el
se
Sy
stem.
out
.pr
int
ln(
“Youar
eat
eenage”
);

4.
4.1.
3Nesti
fandNest
edi
f.
.el
seSt
ruc
tur
e
Wec
anc
odeasmanydependents
tat
ement
sasweneedwi
thi
n
ani
foranel
ses
tat
ement
.Suc
hst
atement
swi
thani
fins
ide
anot
heri
far
ecommonl
ycal
l
ednes
tedi
fst
atement
s.Nes
tedi
f
s
tat
ement
sar
epar
ti
cul
arl
yus
efulwhent
woc
ondi
ti
onsmus
tbe
metbef
ores
omeac
ti
oni
staken.
synt
ax:nest
edi
fst
ruc
tur
e
i
f(c
ondi
ti
on1
)
i
f(c
ondi
ti
on2)
s
tat
ement
;
Exampl
e
i
f(i
temSol
d>3)
i
f(t
otal
>1000)
42
bonus=50;

synt
ax:nest
edi
f.
.el
ses
truc
tur
e
i
f(c
ondi
ti
on1
)
i
f(c
ondi
ti
on2)
s
tat
ement1;
el
se
s
tat
ement2;
Exampl
e
i
f(i
temSol
d>3)
i
f(t
otal
>1000)
bonus=50;
el
se
bonus=0;

4.
4.2I
ter
ati
onSt
atement
s
Tomaket
hepr
ogr
am mor
epower
ful
,al
oops
truc
tur
ecanbe
i
ncl
uded i
napr
ogr
am.I
tisas
truc
tur
ethatal
l
owsabl
ockof
s
tat
ement
stobeex
ecut
edr
epeat
edl
y.Abool
eanex
pres
sionwi
l
l
beeval
uat
edwi
thi
nthel
oopi
ngs
truc
tur
e.I
ftheex
pres
sioni
str
ue,
t
hebl
ockofs
tat
ement
scal
l
edt
hel
oopbodywi
l
lbeex
ecut
edand
t
hent
hebool
eanex
pres
sioni
seval
uat
edagai
n.Thel
oopbody
wi
l
lcont
inuet
oex
ecut
easl
ongast
heex
pres
sioni
str
ue.I
twi
l
lend
whent
hebool
eanex
pres
sioni
sfal
se.Javas
uppor
tst
hreeki
nds
43
ofi
ter
ati
ons
tat
ement
s:whi
l
e,do.
.whi
l
eandf
orl
oop.
Chapt
erFi
ve(
5)Al
gor
it
hmDesi
gn
Al
gor
it
hmDes
ign:i
sal
laboutpl
anni
ngt
hes
olut
ion
5.
1Or
gani
si
ngt
heSol
uti
on:
Cer t
ainor gani zat i
onalt oolswi l
lhel py oul ear nt os olvepr obl ems
ont hec omput er .Thet ool sus edi nthi smodul eandi ll
ustrat edi n
chapt er3i st hepr oblem anal ysisc har t( PAC) ,whi chs howsa
beginni nganal ys i
soft hepr obl em.ot heranal ysist ool sincl
udet he
structurec har tori nter ac t
ivityc har t,whi chs howst he over al
l
l
ay outors truc tureoft hes olut i
on;t heI POc har t,whi chs howst he
i
nput ,thepr oc es sing,andt heout put;t heal gorithms ,whi chs how
the s equenc e ofi nstruc t
ionsc ompr i
s i
ng t he s olut i
on;and t he
fl
owc har ts,whi char egr aphi cr epr es ent at i
onsoft heal gor ithms
andpseudoc ode,whi chr epr es ent sal anguagel ikes oluti
on.The
couplingdi agr am s howst her elat i
ons hi
pbet weent hemodul es
andt hedat aneededf ort hemodul es .TheDat aDi c ti
onar ylistsall
dat evar iablenamesandt hei rdef i
niti
ons .UML( Uni fi
edModel i
ng
Language) i s a bas ict ool when us i
ng Obj ect Or iented
Progr ammi ng s truc ture.Toanal yzeapr oblem and s etupt he
mos tef f
ici
ents olution,apr ogr ammeror gani zest hes olutionby
usingal lors omeoft hes et ool s.Whent hepr ogr ammerdoesnot
uset hes et oolsdur i
ngt hepr obl em- solvingpr oc es s ,thes oluti
on
takesl ongert opr ogr am,andt hef i
nalpr ogr am i sl es sef fici
ent,
l
acksr eadabi li
ty ,andi nc reas espr ogr ammerf r
us trat i
on.

5.
2Documenti
ngaSolut
ion
Af
terappl
yi
ngthi
sProbl
em sol
vi
ngt
ooly
ouc
annow doc
ument
t
he s
olut
ion,t
he s
olut
ion doc
ument
ati
on c
an be i
nter
nalor
ex
ter
nal
doc
ument
ati
on.
5.
2.1I
NTERNALDOCUMENTATI
ONc
ons
ist
sofr
emar
kswr
it
tenwi
th
t
hei
nst
ruc
ti
onst
oex
plai
nwhati
sbei
ngdonei
nthepr
ogr
am.

44
Pr
operi
nter
nal
doc
ument
ati
onens
urest
hatt
henewpr
ogr
ammer
wi
l
lbeabl
etol
ear
naboutt
hepr
ogr
ami
nthel
eas
tamountoft
ime.
Good I
nter
naldoc
ument
ati
on s
houl
dinc
lude s
ucht
hings as
peopl
ewhohavewor
kedont
hepr
ogr
am,anabs
trac
toft
he
pr
ogr
am,var
iabl
eus
age,not
esaboutt
hedevel
opmentoft
he
pr
ogr
am,andany
thi
ngel
set
hatwi
l
lenabl
ethenewpr
ogr
ammer
t
ounder
standt
hispr
ogr
ami
nthel
eas
tamountoft
ime.
5.
2.2EXTERNALDOCUMENTATI
ON i
sfort
heus
eroft
hepr
ogr
am.
TheENDUSERwi
l
lus
ethepr
ogr
amt
ohel
psol
vepr
obl
ems
.
Pr
operex
ter
naldoc
ument
ati
onens
urest
hatt
heendus
erwi
l
l
havegoodi
nst
ruc
ti
onsi
nor
dert
olear
ntous
ethi
spr
ogr
ami
nthe
l
eas
tamountoft
ime.
Ex
ter
naldoc
ument
ati
ons
houl
dal
soal
l
ow t
heendus
ert
ofi
nd
ans
wer
stoques
tionsar
isi
ngwhi
l
eus
ingt
hepr
ogr
am.
Goodex
ter
naldoc
ument
ati
oni
ncr
eas
espr
oduc
ti
vi
tyf
ort
heend
us
er.
Ex
ter
naldoc
ument
ati
ons
houl
dinc
ludes
ucht
hingsast
utor
ial
s,
i
nput def
ini
ti
ons
,us
age i
nst
ruc
ti
ons
,ins
tal
l
ati
on i
nst
ruc
ti
ons
,
c
ommand,andany
thi
ngel
set
hatwi
l
lal
l
owt
heendus
ert
olear
n
t
ous
ethi
spr
ogr
ami
nthel
eas
tamountoft
ime.
Ex
ter
nal
doc
ument
ati
onmaybepr
int
edorel
ect
roni
c,s
uchashel
p
menus
.Doc
ument
ati
onofy
ourpr
ogr
ami
sver
yimpor
tant
.
5.
3Test
ingSol
uti
on(
Eval
uat
ingTheSolut
ion)
Whenyoursol
uti
oni
scompl
ete,i
tisi
mpor t
antt
otes
titt
omake

45
s
uret
her
ear
enoer
ror
sandi
tmeet
sther
equi
rement
swr
it
tenat
t
he begi
nni
ng oft
he pr
ogr
ammi
ng pr
oces
s(t
her
e ar
e many
pr
ogr
amst
hat‘
dri
ft
’awayf
romt
hei
ror
igi
nal
requi
rement
s).
Tot
estas
olut
ion,t
hepr
ogr
ammers
elec
tst
estdat
a,as
etof
val
uesf
ort
hei
nputdat
aoft
hepr
ogr
am,
andf
oreac
honewor
ks
met
hodi
cal
l
ythr
ought
hei
nst
ruc
ti
onsoft
hepr
ogr
am.Car
emus
t
bet
akent
osel
ectt
her
ightdat
atot
esti
twi
th,asnotal
li
nput
dat
awi
l
ltes
tal
lthef
unc
ti
onal
i
tyofy
ourpr
ogr
am.I
fanybugs
(
err
ors
)ar
eident
if
iedi
nyourpr
ogr
am,t
heny
ous
houl
dcor
rec
t
t
hem.
Forex
ampl
e,i
fyourpr
ogr
am r
equi
rest
hataus
erent
eri
nteger
s,
t
henwhathappensi
ftheus
erent
ersac
har
act
er?Yourpr
ogr
am
s
houl
dbeabl
etoi
gnor
ethewr
ongi
nputandas
kagai
nfort
he
c
orr
ecti
nput(
ani
nteger
).
Si
mil
arl
y,wheny
ouar
edeal
i
ng wi
thl
oopsorc
ondi
ti
onal
s,y
ou
s
houl
d beabl
etes
tifal
lthes
ebehaveasy
ouwoul
d ex
pec
t.
Ty
pic
aler
ror
soc
curwhenawr
ongnumberofl
oopsar
ecount
ed
(
forex
ampl
e,c
ount
ing f
rom 0or1)orc
ondi
ti
onal
sar
e badl
y
or
gani
sed.
5.
4Codingt
heSol
uti
on
Onceyouhavec
omplet
edt
hes
tepsdes
cri
beds
ofar
,youhave
f
ini
shedanal
yzi
ngt
hepr
obl
em andor
gani
zi
ngt
hes
olut
ion.The
nex
tst
epi
swr
it
ingt
hes
olut
ionoft
hepr
obl
em i
ntoac
omput
er
l
anguage—t
hati
s,c
odi
ng t
he s
olut
ion.You wi
l
llear
ntoc
ode

46
s
olut
ionswheny
out
akePr
ogr
ammi
ngl
anguagec
our
ses
.

Chapt
erSi
x(6)Sof
twar
eDevel
opmentCyc
le

6.Soft
wareDevel
opmentCyc
le
The devel
opmentofa sol
uti
on t
o a pr
obl
em i
sa c
ont
inui
ng
pr
oces
sunt
ilt
hepr
obl
em bec
omesobs
olet
e..
.i
sthepr
oces
sof
under
standi
ng how a s
oft
war
ecan s
uppor
tbus
ines
s needs
,
des
igni
ngt
hes
yst
em,
bui
l
dingi
t,
anddel
i
ver
ingi
ttous
ers
.
Ther
ear
efi
ves
tepsi
nthes
oft
war
edevel
opmentc
ycl
e.
1Anal
6. ysi
soft
hepr
obl
em.Thi
sinc
ludesanal
yzi
ngt
hepr
obl
em
t
oident
if
ytheneededdat
a,t
her
equi
redr
esul
ts,
ands
omei
deas
ofhow t
opr
oces
sthedat
atoac
hievet
hedes
iredr
esul
ts.The
PACi
sus
edi
nthi
sst
ep.
2Desi
6. gnoft
hesol
uti
on.Thi
sinc
ludesdec
idi
ngwhatmodul
est
o
us
e,howt
heyi
nter
act
,andnami
ngt
hevar
iabl
es.TheI
POc
har
t,
t
he i
nter
act
ivi
tyc
har
t,t
he c
oupl
i
ng di
agr
am,and t
he dat
a
di
ct
ionar
yar
eus
edi
nthi
sst
ep.
3Devel
6. opmentoft
hesol
uti
on.Thi
sinc
ludest
hedevel
opment
and t
est
ing of t
he c
ode f
or eac
h of t
he modul
es.The
devel
opment of t
he c
ode i
ncl
udes t
he us
e of al
gor
it
hms
,
47
f
lowc
har
ts,ps
eudoc
ode,UML and t
he c
ode i
nthe des
ired
c
omput
erl
anguage.Whent
hepr
ogr
am hasbeenc
odedi
nthe
des
ired l
anguage,t
het
est
ing begi
ns.Mul
ti
pl
edat
ashoul
d be
us
edt
omakes
ureal
lpat
hsoft
hepr
ogr
amar
ecor
rec
t.
4I
6. mpl
ement
ati
onoft
hesol
uti
on.Att
hispoi
ntt
hepr
ogr
am i
s
r
eadyf
orus
e.Thi
sinc
ludesmar
ket
ing,t
rai
ni
ng,andf
inalt
est
ing.
Manyt
imesi
tfi
rstgoest
hroughs
elec
tedaudi
enc
etof
inal
i
zet
he
t
est
ing,
bef
orei
ti
srel
eas
edf
orgener
alus
e.
5Mai
6. ntenanc
eandr
evi
ewoft
hesol
uti
on.Af
tert
hepr
ogr
ami
s
i
n gener
alus
e,i
tmus
tbe mai
ntai
ned and r
evi
ewed of
ten.
Mai
ntenanc
einc
ludesc
orr
ect
ion ofer
ror
sfound af
teri
twas
r
eleas
edandmi
norupdat
est
othepr
ogr
am.Thepr
ogr
ams
houl
d
ber
evi
ewedof
ten.I
fther
ear
emaj
orupdat
est
hent
hes
oft
war
e
devel
opmentc
ycl
est
art
sover
.Ifaf
tert
her
evi
ew,
thepr
ogr
ami
s
deemedobs
olet
e,t
heni
ti
stakenof
fthemar
ket
.

48

You might also like