DAA Revision Notes
DAA Revision Notes
Fnknes
llgo mual krmnate ofr finile no.g, skcps, canl goon fefe
2-Debiaitents
kadh slep mual be cleas wwbigucusly daioed
3.
4 Output
Alao Chold roduce at leasl 1 Bukpal by pace Ming lnpal data
•Speficatin
is malus dsenoing algo in omal ng Methnads
2. Pseudocede
Oecribes algo uring Combntion e notwral
4
Pegrniy kanguago
Jpeaiting decy wsng a progranmig bang
Jav, C ... dhs is wnambiquos & prec/ R bil less
intutie or nol eay to undereland
Asymphtic nalycis.
Js a melhod to elescnbe the behavioww clgo (Olen
ehin
tne Inpal Srze grous touomcb inynity & pro vidlo a way
to evauot io etticrercy by foniny en performance.
helps to ompou diftpereñl odgo bard on tme & Siace
lonplerity
. Asymthhc
Mothemaical
Notatiens.
Basl Cas.(o)
Repnescnls miaimun time o& spnce fengteety uquie d by
algo oith all possible nputs.. Nh an tdeal titualioscohene.
Pertonancc Meaucngl
To undestarsd the qfficiencey algo
to evalak & compal baud on pimang copcc
1.
Refes to the ameznl time an algo taks to
Condeks Sk erecuhisn as aa functien e n (inpal size). Melhas
to measuL Ione Cerplexity:o tounling Openilions
3. Empncal eawemenl
4 Benchmkiag
3.Auriliar Spuce
Q. Bac Casc
Cekrmint hase tase 's tint Complesiky. Ba
Cac
hLbess to Instance ga probem, cehtch han be solwed
dvecy letd turtnin casiLon
4
Space lempleciy
lensidw te dpace ied by secustien Snck for
To)L
TlA)
(I
+c
n |)
(oterwise)
Base Case
Recanence Relatibn
Substitatiy Melaud
T(a)-T6)+c0
To)- TA)+L0Subanay
lnd so
, n)
sas Ca), so n à reolaced bye
we gzl tine
klhen ecY6TO ago
> As we
Yenches
knouo,
FnyfT) = T(/)
So,let asume Q* = n Then,
- T) + ke [r)-1)
|+kC
I+ Lognc n2* logn - logak
Mastors Theorem.
To)a n
n'0 LABAD
oC)
Ans a
Logg
n loglu(n)
n°.u (n) u(n) > 7(n) uCn)) a-1)
hn) ftn) c.
nlo9
- (ogn)".c
tleve e is re wntten os (logn). c,ohich i
u evenuallyc
hon) = (togn)°. C
T(o)- o ( ogn)
Cperalioas
Oiyoun Set data stralune lao kncon as
Unien Btind) is used to kep tack ef disjanl Subset
cf a patieulan sel. Operstieni l Jndl
Jind
. Drctionaies.
Dis toaries ane absthacl dota types tnal Store
Operalions : I. Insest
J. Search
(Put)
lget)
3. Delek(oemove
(o
Inserl
Adc oa neww key Valwe Poir
2. Seorch
Rehiee Valve asociated wstth given kay
3. Delek
Remove a key- Val pir bascd en ky
Cuaph lgoxithns
EDUC
almasl
Bnany Thee kach node hes d childreeh lsuft & sight).
K
Biny Seanth Trec
d oioas te ohee te left child ds leo lhan
he poenl neole & the xighl Chilal is gnaler
3. Balancd Thee
Tree ohich maiabins balanced heigh) to ensal
ollogn) operatins.The height o, beft& sight Subbecs
4 any node dtbes by atmisl a Gpecfie talee,ohlen
dor example, AVL tres & Red-black toecs
. Tree Algoithns.
t.
Q.
Birary Jorch kfieienl
Tee tavesal
emching
posl-orcler
tee
tavi
,
3. tleop Sott Wainy binn head to so7t elerenls in oalogn)ioe
Date
Page No.
UNIT: 02.
Oinde d Congueu, Brule orce and Gredy Method
vide ogaupy
an algoi thmy, tohere
opproach to design
preblms
a boken doen unh Soaley Sub
pmobum s
embins
and sole each Sab prlmm becuusilly. heo
Solution to solue tie briginal ppbln
Gereral Melhod
b.lenbel absthatieD.
C- Merge Sost
dQuick Sosl
e.Brony dach
sSemxch
Algoilhm
DAC (P){ l DAC DiridleAnd Congue Y
/P- Problem, h Piu Smal
SIP)j Hhen it solued dix2clly ceitheil
tuthu dioded it
elkef
diride p inb ale PP Po.
DAc(P,)... DAclP)
apply DA (e.),
a soted omoy
wlaking
1: Stel with & poinks, koo h high, onich porinit ealy poins
.
to beginniny & end of the amey veupeclively.
kowt
& lolin lte mid, mid > high
H mid> key, ten sct high to mid-l & Seoreh the left bod
4. Repal unil s
elenrd is found or amay is exastel.
BS(on,ony )
igha len lony-l;
( hrn
[mdJ--
(on
re ; mìd
trget) /Elermen found
Teturn -1
So Cempleaty
o Recursiwe Mettad
Algoathm ot
RBS (Lib,ky)
4[lazh){
Tehurn ;4
Tehun midi
4Ckey< A(mud]){
rehum Ras ll, mdl, key);
elx
Tehurp RRS (md, h key))
Roll
No Lecturer's Signature
Jime (omplexity is Same as itealive veLon ,
nlakig
a. Pivot Seleel an elenenl as pivot (Iial, kasl, mid o vandm
lemenl)
Jime Comperity
kxampla
80 qo 45
SO 90
P&Q CrOSsed each other
IS (35) 80 So toosuapQAV
Pivot
Sub ana Sub nad
Roll No. Lecturer's Signature
P P
a ) + oo
P
80) SO (a0)
P
+ o
(G0 so
on qo
Sorted y i s a0
Merge So
Divide i Cenqves olgithrn to sorl amy
Working
Example
6 4 Q L 9 3S
3S
3 s
3 S
enbaladn
MSa tencept thad hidydetads e ontel
epimum.
Ckps (Gymeal Melbod)
at each Stoge
Applca ti ons
a. knapSack problum
b.
O. Job Jeqvencing oHh deadlines
C. Munimum lol spanniny tee
d. Singu Sbwce Shoi kesl poth proble
recdy Aproach
talcing
alen
as much
u as possikall
kaupsack
c! cach
highasl
e Ihu teks
you
eplimaly
Can -laku frichbnal
or the fraclional
pasb oh itm
knpsack problun , Whusd
Goboqusncicg
kxample
ltems 3.
Vaw
weigh
Appoach
kxanple
&
Ji
(-2) J
(o-)( J,, Ji
Js (o-)
(o---9 Js,J,J
4-0
Js J,Ji, J
J4 Soutien
Date
Page No.
formed
kaample
DPgs Algputb
inginty
f. The algo demioas cen all noes hae ban Visied and ad
Kxample
|4
14
22 14
7 l;23
L, 2, 3, 6
4 20 ,23,6,4
20
| Bxkk Eoxe
A Shaight (orunrd arpoadh to Jolue problems by caploig
all possible opians. Smple bud incthecent for large inpats due
to theiu high time Cemplexty Algoithns that follouis baule
Appreach
EOUCAY
APPRD AC
R
|3.
a
the
plane
paiw
coith
e
set
poinls
n
thad
polnks .
Appronch
Example
P- R P- P, Pa- Pi
P, - P3 P3- P
P) - P+ P>- Pa Ps- Pa
Smne Conpeity n)
o
Appocach.
Slont oith the ft mast pont, and find the neñl point
to wrap te set q poinb by mainlainig the Converity
Ime Compeity
or Convex polygen
o cnh) , ohere h u no. poinks in hull.
Date :
Page No.
4 Axlautve Seanc
to eodh through all pesble outiers
Mgonithon
all pemiblu solutiens o a
4 a probum. Used to cvalua
Taveliog Jalesgan
Walecman Paoblem
Algorithm to fiod the Shorhesl pesibe roate dhet
visik Cach pouat exacy bnce ke twms o the origlo poiat
Approach
Evaluat all the rautes & tind the ene oith the Sha lest
• For permutation
A B D ,calculate the
distance: 10 +35 +30 +20 = 9.
• Repeat for all permutations and find the
minimum distance.
PDERAB
CGiven a set og iens,each with a weight b valoe
Approach
me lomplexity o (a), nà
ValveD
I,
13
, Al possible
(I,,I,,Js
(5) (o) (s) = 20.
(ombinal
soln
ipns.
ion)
DAssanreol Proble
Algori thr to minimlza total cost by csigoing
n oorkes to m jobs
jobs.
A proach
kvaluas oll permuttion
possibl job asigomenb &
Example Je
Pi
Peymutati bns J Je J Je
P, P P) P
P P
Al possibe Combina tiont
Pi Ps P
P Pi
Uynamic Programning, Backtackiog ancl Baanch Bano
Page No. Date.
NtT: O3.
Dynamis regragmiag
An apprach to deigo algouithns fo solae
|Usc a QD
a0 amay DplALA] where iu the ikm idelen k& Wis the
w
Recuyence Relaten:
city ealy
ence & cns to the orign CiHy
Appo ach
approuch tb represent
Uscs a bmask oynamnic programminy
Approach.
a. alyoitlm ib uscol
krzriulluy loyd- liarshull
b. Vec o mahia DJS1, ohere Depre <nts the Sho kst
Appaada
GReliablky Desgo
Desigo a bystan wih max sclablity wnng
Cemponents oth qign scliablithy valts al
len shaink.
Approach
Approach.
a
O Jor each choice ,apply tie choice & vecunsively
Call
-lu funtien
ead to a ralid so lutien
ecsive Call doesnt
b Jt the
choiu& back tack.
en undo he
B)Jlevotie Backtrocking
Backtracking algorilton that avoidb we g teursio
ecwio
sing an erplieit stack instead
Page No. Date
Appraca.
a.
a Usog erpbat ack to kaup bak of steale kach Skale or
4Qusen Problenm
dlgonthn to place queens en a Checsbard
Such hat no two queens atack each other.
Approach
Time olo)
enplexihy
(omplexiby ne no. 0 queens
Appro ach
Cayaaty
Apprcach
aloesnt
a.Jnelucle items ene by cne & iy 4e totel weig ht
profit or vale
Page No. Date :
Boundiog
Boundiaq unctiens aN wsed to eshah best possibl
Scution. H thi bound is oorsc thanythe best ercnt
Jouten, the Sub hee à pruned. (or eqval to) or else
bound solution is ieplaed oith Cueal bsl eluhon
Oper bound
or miainka h on problea, an upper bound s an cshma -
Lower bound
For maximiRaton mabuni, oe louer beund is a eshonated
minimuals
Loith cwhent bc soedo
eas Cost Ba B
kC BB aluoays cxplones the least- ost node fa.
Nodw at kepl 9 a miorily qvee baxd on thiw cosl. Jhe
Dkn leads to more
tbi cuznl pruning Since les promi eig
nods ae s ikely to be erploxd
Time o (a")
Spaa
Cemplexity
(ornplenly
is ,
sHl erpenenlal bal managad.
2B&B
In FlFO B&B, nodes
nodes ae
are exploed in t he oroler
Ollknapack Doblermkc)
vae tl
o va upto ts point
Time (omplexiy o o)
Space lomplerity o)
Page No. Date
UNIT:- 04 Graphs Trees
Graph Taaessal
Jho aelos visiing hocls of groph is a sylmae
ManneN do Cxplee the graph
techniquesi
. & galhi
primony graph travtal
ngormalin abeal
Steps
Cngvev it.
r4sr
Jaansitivo one
clo
Tmatiz T where i
or Cach
b. verkx in the graph perform DES Stortiag
facm Sousce ver tex
Wtex
DAG,
-tveyh
ids persibe to
a diched gooph ,
hl the s no
to
•Topoegiçal Orderding
ordeing onties in a te DAG Such
d linear
Steps
topological ordaving
topolcgical orderig
Vsl, usl,T-l
•Indegree y R&R>0, Q2,S=l,
Q -D,Sz Va usT=l
P& R verhtes delekd, tndaree
Taies
AH like data staaluse usd Storiosal
sttrievol of
kya aL Lnaley
Jypa
kxamplei
S- bear, hel, blds buls ack, Sfop
C P
k)
a cingle oracer
Sto
id u) C
Kxample
mlze
Lmize
nimize
tnimize
Minimlze
EDUCA
m
Suffia -be
. Exlernal Seonchng
disb.
ypically stoet al
B- Trecs
loith eell
spaihe type g sef- balancig tee
defined prper hes, Codaly iscd tor managing harge
datasds etficanly on disk.
Propzzlics
Dzevatiens
bn the he
te stucte
Tioperlies
a The no keys n
in each noode ranges fro Ala to B,
enaing
the taee emous balenced .
b kach nede con hav bctween A& B ehildren
Operatons
ehere n s
n is no.
no keys dn
Und: os. Cempalalietl lemdary S Forallel clgpilams
Page No. Date
Nondsleseinste allbo NP
lgo thal Can maku mtlipla chorca al eath.
Step for ib nal oclieo.so we cant preditl the D/P
Redurts.
Censide decigon Trobams P & Pe
P
P. with
with
Onpal
Japal
(I)
(I)
algo la1) het
alGolA)Ohane Aa
, AI
is knoLên
unkneeo
lenverled nto
P, s Teducible to Pa
I,l)=IoAlgoalhm
A
Jolustion for P
be decisn prcblem
A.B. C NP roblums
NP hard .
. NP-Ceyplel
A prelblem th u both in ND A NP- hord s
NP
HHord
NP Cempleke
Watisfablity Dobjen
SAY Standh tor Beoleon salatiability
podun. Dchiaifi ent Gi a Boolearn expiesion
expesien wiay vaiables kogical h operaliens ika AND.
OR, NO7), the SAT problem csks uhelhw these
Example
Boolean Expresni
{s thexe an assignnnen] tah alcA ttrat to Z, ysz
thd maks Ahis gomla tuei
assiannt
Pros
syatms
PRAM
PRAM ands tor parallel senclon occss machune
Vaiants.
Procesas Mi amCnopd
amcngd in a d
dicly itb us
procesoó lem Can lemmunioal erly
solwrel
e ovigul probum Shen toch
secuiiely ln pasallel ancl
.
snallew Sub- prtlglems
( Recusit Doybung
he main idea is o saz eilh small subsels&
erathly lembing thum an pas chll he Lohele prtldn
:
ists
theiery usirg a
buoy
Soked lhsk
Merginy
Porald pelix Sum(an)
3. lend Operations