Bcsol
Module21L Fundamentals cf
Inrouc kon: what is on
Plgothne proslem solung
|Fundamentals of the Analyos of agothnEeng
haly's Fhamewon, Asypb Notabas ad Bant E7%ierey
|Classo, Mathematical Analyfs of Non reCuS'Ve Algorithms.
|Plathematcal Analyts of Recusive Algoitns.
BTute Force Ppproache Selecion Sot and Bubte Sont,
Sequental seavch and Bsuke Fovce Strig matching.
Iotroducton:
has come to efes to tbe method
Algostim
that br wed by a Compuber or the seluton
|0 a prDblem Thi is what makes algosthm dferest
words &uch as bces, technzue or mthod.
uhat is an Algoithm?
Js deRnedl os ointe sequere 9 urambigus
insou ctons Biloued to acemplith a go task "
Pkes Pratuctg the Yell, the algorthm shoud
Zeyminate
Psoblen
Solulon to aa gn prablem is expresed in the form
of gorthm, alg conveted inb a pragnam, Pugsam ahen
Eis executed acoap the Il and prdues the destred yo
5elore owing any pngam, the &olubon has to
Be
be eaprese in the born
Propestes of an algortri
Znput £ach algorithm 3houlol ha zeo or more
pS The tange 2 ps Jor which
Cors Shold be Sabs bed
d Output - The alg. Shold pnouce c0vreet reselk.
ha to be Produed,
AAleast One Ol ha
3"9eritenes Each instru ct'ona 8ho ld be cleas
sho uld
hnanbguous and precle.
E}fecven es- The inotycor Bho ulot be Airple
and should bsanshm he gn.2lp to bhe
dested
5. fiaibeness - Algoithn tesmainatas alten a finite
Steps The b'me Jo terminakon shoutd be
Short. (all cases, while trace out
khe intr uchons an
agonitm).
The Study 2 algoithma ine tude h areas
|· How to devise algosthmo
a- How to valslate algorthm
3" How to anatyse
algorthms
How to test a progAam.
How to devese
algonthms
agortom an Qt whwch may heveY
be fally automated.
How to Val'oate algonhmi
Once s devsed, it is hecensaneg
Show hat computes the cossect answer Por all possis)e
Paspose of the Valoakon is to assure us trat this
wi) wole eavety
independenty o tbe issueo
conceming the pagomng
ostken n, Once Val'oabon
g
akon complete, progam can be
it will eventually be
wken This phase refered as pogam prong or pngam
Verßcalon.
low to analyze algoithma;
petfbimanee araly?s
vePers to the task deten how much
COmgubng me
and stvaop an
algonthm Teçuires
It allows to make quanttatve judgements
out the Vale
abou one algoithn
over anohes.
It allouws to pred'ct whether the S)w cwil meet
Gng ekency corstra'nt that exst.
"gontm perfor in the best case, worst case,
|aVerage Case
How to test a progpam
Testing a program consrst
or Pertov marce measure ment
Debugghg Ig the process o execating Prgraa
Sample data sets to detesmine hetheY Jaulty renutk oceu
f So. to coyect thern
da ta.
Cannot Ve* the
covrectnesS o DJp On Sample
Deb"gsng
but not to
Can
Only point to the preserce
ther absence.
enors,
follow the shetego more than one
Prgammen
develep prgrams ovov the
the ame prpbem and compave the ops
Produed by ther Prgam. IP Olp match, then there is a
corred " pryof of
jood chance that they
are
Covvetnes s much nore valuabie than
a thousanot teste.
|Prolirg - Is he proces esecuhing a covvect Prgam
and measukna the Bma and Spae it ta
t
dotasek
Compute the relh .
Plithn dribead in many kay
the
l nahnas langae the kngeh- male sare that
Tevsing instruckom definite.
d aing pseudo code coverson.
Fundamertala of Algotie Pem solunspoce tneot in
lhe algonihn eign and anyos
Pnem So l
ndenstanons the Poblem
Aseentaining copeb:k of onpukond devie
dectston Edoct Vs epprotinate Slwihg
ma)Cng
Date suctues
SpecBeabon9 algorg
an
Poyve corrertness VeriRcaban
| Tngemat the agorithn cad'ng
the prpblen ( statement the poblem)
understand'ng.
inderstand the pmblem
Thoroughig bnders
Ped b iden the prnblen eçutrements
Whethe Prngnam YeGuires otera ckon wth dhe lser
b ît ptuces the olp Gnd howwto prerent the De
3. clanhy the doubts in dhe dersption dhe pm
4. know what J)p o gve,
ave, what olp is obBalnes (Jlp to
the alg. caled intane n the probem)
woY Jes
not the one that
The corvect atgorithn is?'s
|most the Sme but one thot woses covrecty Jor al
|egtmate vales (Ip)
AScertaa the Capabbes a omputabornal devtee!
I: Arch'techre dhe devte
based on Lhese there are
a- Fos bhe devlee bared on Von Neumann archis.
in which istrucbon and data are Bhred in memoy and
rognam ave ereeuted Bequentaly degn sequen ba!
us On the m) in which the
algorithm. [SA specBcaly
|insbucbor executed One aftey anothon] sach a mle
Called Tandom access ]c
b If a devee is capable erecub'rg the rshrueons
in
parall. detgn pavalel aGort LPA are Tun on the mle in
whe h the iutu cho no pa vale)
d Bpeed g dhe devtce
Probler mktary aplcateno
COm muncaBon and 7eal toe pnolucts Buoh aa mobiles
(wy about Sped dhe device.
EXert Vs apptmate so)ng
algonthny based on tbe 0/p
olp obtained
Edact algorha:
Hlgor thrns that sÙl ve the pnblem eraetly.
Agoothnn or ionng. seorching. ng matthg
|braveling Salpeison prabsem, knapsaclt pro siem ge raet
Yelt.
Appotmate aleortha
Algorthanthat solves boe probien appnxtnatty
non Lreas eguakons
Data structuna
Choose proper odata structure
bvel dned algonthma and data Shiuc tores
wste efRtert progama
Algorth + Data structue =prugram
alçovidho
Alqorithn dgn teehntque - 1s a geneal metod
|Solwirg a pobem tn the Jotm B algorhma
1· Brute ore- Stragt Joxward teehigue with nalve app arh
2"vde &congue - pbm is otvted inb Srmala imtances
3" Dee ear e conguer - instanee siz 's
oecveas eol to Bove dhe phm.
Tram rm 8 Conguer - instanee s mpotked and oved
S" Space Bne tbadeo
Dynamie prgam-The rerult Bmalle,re
instare are obtahed to solve
technique
To Bolve the pbmi locally opthmel
Bianch and Bound cec'sion are nade
3 mhoole
| Nahral
languag
dPseuclo code
3"Flowchart
Naval lançuaget
Can be Wstten in Eng'sh 'ke stabements
tle mathemabral
veny enpressons
Flowchovt:
Piconal [Link] 9 an agit,
Cons?st insbu chom that aYe aned ot
algorth
Steps ae
ctveleo and connertna avows
Shapes eprestnt Vavious opevabons Ehat ave caied out.
aows Yepresent the Bequence in whch there Opeatono
|are camed out
unclevsland
ured b hel the pogrammer to
bhe dage
Manly
he pam
PSeudac oote.
atra
7s a medhe d q repre eneng
prgammng ongage
\lerguag and
2$ a misature a nara largage ano
|angpag censtructs.
Prooß , algothm's corectres
Ater designry the algoniton. prove its covveetneas.
the
progammen responsLhy to pove tbhat
ehe algoritm produces the re quted lp every eghmate
|Input.
a. The roof CoYrecnes abgoithm is
done mathermabtal inducon.
an
nomaty
Analyts algosthra.
s a a talk g delevmhg hocw
mech comgutng bime ond Storage reçutred by an
|algothm Also called per brmance analyis -
Soluton b be pbm can be obtaned ned wtng derent()
agonithm choose the most efeient algondhm
Tme efierey - tnd'ales how doot the alg. Can be executed
Space efRiency - in l'ates how much (minimum) eatra memny
is wsed by the ecuhon.
Jmplementaton. ( co ding an algordhn
Sokcteod Shouldt Bupport the Jeaturso
Ihe language
nentoned in degn pha
equvaant
Cowet it into an equialent prgammg ceolo
Tetng 3 a pragom s an
acKuhy that can be
carred Out in a phases
Pgm prouces Paulhy
Debugg"a resullb
chelce
then the
whethes
has to be corected.
Jound
progam
tBne and Bpace
Yequred y
measutg
correcbed
pragam
Vald &et
Analysts yamewor ie
Parpose of agoathn anaby's ts to de»tg most
eBetent algorihn
Efkciency 3 atgonitm dopend on & fceors
|· spe e PRctency
.Rme efRciery
Tooe efc'enoy - tndtater how sast an atgorthy in quesBÓn
Spore eReieney - exha &pace an lgorittm requlrer
Alnast al algorithm Tuns longes on fagex Jps.
Iis Segirat
Jageat to investigate algontns effriery as a
% Bome parameter n indaMng the aigothma ip sig.
Measung an
Measure an Zlp s'ge Be a spel chec leng g
IP the alg. exa mines indtoleas charactes i
measare the Siz by dhe O charactes
I? wos)o cocunt Ehe's nanber
by Procesing
Units me wng Tanning Rme
neasung.
apprnach s bo Count he Bmes each the
openaons is evecubed, it is Bcult.
oh's
rmast mportant openaton of the
Idenisß, dhe
alqontn called ban?e opesatan, bhe operak'on Contnbuknd
bme te
Brne, comgute
bote operaHon is ecutedl.
Ba'e opeakon - mast Brne consunig opoaton in
the innenest Loop
T(n)- unning Hnme of a prgam
Bme 0fof an
Cop - erecu lBon Bme an algonihan's ba opeat'on
On a
pavkculan Compute
C(n) - ho this operaten needa to be
T(r) 2 Cor C(n)
OYder
3
n
nlog
Case ePctencies.
worst case, best case and aveage but
an
Rennos Bne deperto not on
also on the spee'Beaon
Eg. Bequenbal Bearch
ito
whle
if ien Teho ee retuin -)
Io w04st case When there are not a matchiy eements or
Be irst matehirg lement happer to be be Aast one on dhe
st, bhe alg male the
all possible lps 2 Size n
The worst ase
e¥Bciency B the woxst cese Jp Sie n, lwhch is an
o cohth the alg suns he al
Posble ps dhat sie.
Cworstco)en
be best case an alg is 6 e!Bene h dhe
best cae Ijp y sie n, which is an
whtch dhe alq- Tun dhe fatest among al pasSbe 2jps
bhat Size
For Average Case, make Some Gasumphons about passib)e ps
* Both bne and Space efBeiencie are measu reol as r
of Bhe alg: Zjp sige
Tne efhriency ss measured by counbin the ho bmes
Ehe basie ope raton is exetuted.
algorithna ra
Spare efiency is measured by ounng the ro%
ie
anits
memong ants Consumed bu
by he tg -
Bom e
abgonihme may dfor sznReantly
the Same Size for Buch atgoithm, ds#gh
case,
best case etdencies.
bet he wost capi
averag
|Boyic e fieny asHmpbc caase
J- indiate the Bme of a pgm Corstant.
Brne prga is Jogeithm'e. Tht
OccuYS in progams Aavger ponbems
hat 30 he
by*g Teout mg the prslen sge by a constant Zochr at
each terason a dhe loop. (eq bhary sea
dearch.
Tunning Bme ofa progrom
n-Tunning
elemere fn dscendla ovder such
nlagn- algonthm o Sovt ascendng
sovk, heapsor.
quck Aort,meg
n?
n-eurmhg Bne of a prgnam is quhat . The algonhm
nomoly haue aleops . cesy sobg gonitn Such as
busle ovl, seleckon Sovt. adtkon and Subhachon g
matsce
n-suning bme of a pgnam is Cubt. The algord
have 3 loops mabs mulbipliealion, algorthm to sohve
Simultaneos equakons cwoing gaus elimihakon nmeha
Bme of anan algon is esponebal- cogower
Tnnhg Bme
Henbi
Bnning bme of an
gonoate al! pemutat'ons ) set.
Asynpote Notetons'
Big oh notakonl o)
5ig Omega notabon()
B'a Theta notaton (a)
tn) and g(ns be ny non negve tora. ned
in the Set naural numbou
to) - algonr's
alo ihis rning ne
gCn) Some
Snpe frs to Compare the
khe count wit
Tn hoxmali
O( gin) is the sel
allZns. w'th a &malles
gr) ( to cwithin a corstont
malliple.
neolna) lipeon, have Bmaler order 2 gocth
loon +se o(r) than gcn) =n
n(o-)eo(ni) has the 8ame order 9 gocdth
quaghoke. has
4uacralc,
as na
bo cubic ghe ovder og qooth than
e9n)) is the Bet all cwfh a
lang
within
to coithin a Constant
me oder 2 g50uth as qin) (to
mutke. as n
nea(n)
3
Same odeo
0(3(n)) s the set all Jo that have tbe
3(n) to within a Corstant mulbple
to
with a> is n 9(r)
ÉVerg
Formalr by
&aid to be in O(9tn)), denote
by &one Corstart
t(n) ¬0(acn), f t(o) s bound eod above
stSorme
mukpie q gen) Br all lançe n(ie there
Posive Coratar C and &orme neqatve integen
or all n2n
cgtn)
t(n)
doesnt
matter
no n
Prove' loon + 5e Olr
J00n +5 < 0Ùn +n
+n (or all n s)
lot0t n Jceolorn in choosirg spe'fre vales Br contar
c&Dp:
Said be n lenoted by
pastbve
cn)élacn). if tn) s bondagl below by some
Cey if bere
corskant melbpe 2 all
longe
Sore Poskve Copatant Grd Some hon regate inees
no Bch that
all n >no
t(n)
|doent
matken
Prove'
ne)
h3
>n for all n 0
A fh tlr) s 8ad to be in o(gcn) denoted
t(n) eo ( q(n)) , f t(n) s bounded doth cbove and
|bele wby Bome pasibve conbant mutijpln g gcn) or al
sorne posve
extst Some postFve Constant C, and
lange n e if thene exist
Ca Gd Some non neakve fntegon no
C, gin)
tlo)
doer
Prove D(n-i) eo( )
Prove bhe ght in equabhy ( uppe bound )
bound)
Jnd prve Bhe leyt inequalh (Aowe.
b Jer all n za
Poperky invglwtng augrRtube motatong:
analy3e the algosthms that comprse a
To
exec uted pant
Consecubvely
Theorem,
If i(n) ¬0(3.(n) and ln) e o(32 (n)) then
Take , asbitras real
real humbe a,, bi, ag, b (8)
Ehen a, +a, S a maz
Since Ein) e o( 9,(n), tbee ex'st s0me pesibve conatant c
and ome non negckve intgen PBuch that,
far all n2 a
denote Ca max SG,c, Gnd Constde nz max
ineçaivabie above
ao thal lwe both inegualhes, adolhg the a
SC3giln) +392ln)
Hence bi(o) +taln)e o( max S9.c)s2(n) coith
Corstants C and no YeGuised by inton bery
I the ale corsecuely executed
Compnte a
Posts, the aloths ovenall efRetency s detesmined
the past oith the Marqen ovder groth ie its
leat effitent part.
Though the bml olfinom 2 O,2 anod o ane
indspenscHe Rr proutdy thery ahstyat prepesbes , t iss ranely
Conveneint method Jor ooiy s bar on
anpug
lim tln) Smplies that t(o) has smallr ordes g gewth
Ehan g(n
C>0 Bame
Aanqen
Converient than the
imit based appcach
the
One based on the dofinitors, bcoz it take adartag
Pooeshl calealus techn'que, developed hr Computing imiB 3ch
Hsptal
Lim tr) n t(ry
ornula
Sing's In mathematu, &irg's apprpxmakon is an
gend gualhy Jprxiroaken
prothmakion ox
even or smal val gn.
to acrnate esll
|Jeodting
l- Compare the ovden z ghowth %(n-) ard n?
na imm (0-)
Poste cornstant, uchon hae the ane cvde g ghoth
n(o-) ec(r)
ard Vn
Commpare the ovder ghouth 2 gn
bim os
Logn ha a amalle ovoen ghowth than Vn
logn eo/n
3
(opare the osoer
n!
n"
im
(
ghows vey ast. ssl1 faste.
n E ()
unltte big oh, tWe oh