ADA - Module 2 Notes
ADA - Module 2 Notes
IN
C
N
SY
U
VT
withne
the peoceg8 Cenlenues w l a dead erd i.e,a veetex
adjacent uneaited Vesices te encoutesed.
o tbe Vestex t
" At a decl end, algeibm bares up ne eclge Wieled velices
ame aom and ies do coniie wialing
foon there.
" Algtritm erenually halt e allen backeng up he alasding
.IN
a de enl.
Vetex, sitt, te littee betnq
then, all the veolices in the Bame chete conpenent ae he
alauing
4a y uriated
Yeetex haure been iailed.
Vealites lil
C enain, DFS muet be 9esloted
N
ot term
SY
opeRalion DFS
we pueh a Vetex enlo the aSock hen the Vetek Ze ecche
o the jstime and e pop a vetex aee e alk hen it
U
adiacency malix
nunbee nodein qoaph
4oorn ohene the Joavess al ie to be alastel
’ viated andnst
ttat ose
3 ’ Ldictee tbe veeeg
Vaeted.
l Output; u,), nodes v eecuhable focom
Vecloe t
.IN
C
t[ J v
N
SY
des la,n, V, 3,
end
U
VT
.IN
a b, , d, e, bs, 3
ajb, C, d,e,f
C
a,b, c,d, e,
Ca,5
a, ?. a,b, c,d, e,f
N
( a,b, c, d, e,f
SY
a,b, c,a,e,P,
VT
a,b,c, d, e,P, q
h,i
a,b, c, d, e, t,q
h,t,
ab, C, d, e,fqbi
a,b, c,d,e,t,9,
la,be4,e,2,q,5i
a,b,c,d,e,t.9.h
DFS lcavesal
Studied smart, not hard — thanks to [Link]
Toearel Asouk (oe) the Be in thiel, Veoit er pushed ane
PO Pped but o the lak aste ohlanod oeorn
g tep-4 as ahour
o,1
aß
8,9
.IN
DES ee and aaveal e obiainee by lotine, tt he sedpct ceumn
C
N
SY
)
DFS ar osal
U
VT
Fiq :- DFSRee
Nte;
Alter Istarealng the qoaph in DFS, t,ere asene bak edges
tben the qoaph is acyelie. thewe ta a back ege oom som
Vesctex u o te ahcesti V, then the qph ayce.
Analyats i
" Analyata e DES depend ori Be humben valicea dnd hcthea the
adfaieny maoix
.IN
t is conveniet o Ene,it ie
iAeoted
ten a Veste 89 eached e the
inlo eca en e aee a
C aleendy explared
the vestex
hen & we qot a dead end i.e,
be oiont ueue.
N
we delete avesdex locom
Pdeing veices ie, The flee
SY
s[i7e- 0
]BUHce
end
.IN
end'nue
C
" Analyae BFS deperda on the nunbee ef veices and hetthe
N
e otjaceney ipsenenlalion a
SY
0(iv¥E)
VT
C, d, e
a, b,c, d,e, e
.IN
Nete:- Reue ls emply, b t thee asee Beme Veices that ase
et enitel. So, lo the net aubqaph sedo the above poo eduee
a,b, c, d e,* C
N
h
h
SY
BFS
"Rdeainq g veices is obtalnel by looking ot the lavessal
12t ceumn nhee te veslices ave deletecl qoom
queue
BFS Saresal ia obtainel by
lookin ot te output celumn
" VAcolces
loploqical eota qoapb cacan be Vewed a an Bdesine
along a hü zoal ine ao that all lected adqes qo'
.IN
) DFS mettod C
Sousce Removal metto
N
Topological oEng sdulion oblained by thehe BUe 4emovl
the one obtained by tte DFS metod
SY
.IN
a,b a,b,e
a,b,e a, b, e
a,b a,b, e,
C
a, b, e,q
N
a,b,q, a, b, e, Çß
SY
a,b,
a,b, e,f,
a,b a,b, e, .9 b
a,b, c, e,f.9
U
a,C
a
a, b, c, e, . C
VT
a,b,C, e,.9
a, b, c, e,f.4
a, b, C,
,.
a,b, C, e, .q,
a,b, c, a,e, #.9|
- The Ble in hich Velices ae eemoved loon the alaek
sLemored
obtained toeon the laat colum. The P°pped
e, f,9, b, C, a, d ’ poppedd seaence.
Toplogionl oden ia ie obtoined by eresing the
he above
Poppel
Seauence hict te qiven by
d a c ’ b ’ q7 ’e
Studied smart, not hard — thanks to [Link]
Alqethm toplogteal Pden (n,
/ To oblain te genLence fota to be executel seesueng in Mopeloaiti
ajacerey malix e
niunbe Veslicos in the qsaph
hot ooe e nodes
nodeg NY9itecd and
S’ to tnew what ae the
a e tbe Vetc es (nodes nhict ose deal
’ Inelex Yaslabee o
en
iueb t e Veslices ase
.IN
nghac helle t e Gtle in
Popped.
indicctes he Veices in
C he sereseae dee ha
loutput Hes
ase o be exeted
N
SY
U
VT
DFS (u, n, a)
e
olusun
Aralya
Aafacency malsix
Jine DFS funelion is the ne aeaeied o ex eeute
Running
he olenent
Studied smart, not hard — thanks to [Link]
malix ine
Tln) = S |
V=0
DFS
V=o
Veo
= n(n--0+) =n
T[)= n
Time qves by e(n). Fe a
veslic es. Hence, n=lv
Time Complexit ds qiven by elv
.IN
Aaijananey C
N
" Let Gi-,E) be a gopl vohoue V’st e velfes arndEet
a
SY
" Each Yétey io Kiaitet eact elae ie ken Qocom tte iet. So, ene
peeteny acesaing ench Vetex and Ume epctency oaeese
U
D 1
.IN
do net depend ask
and can be computed o o1313’ Sume coluns
Sun ef ndegsee oaeh node
indepondertly
C
les ttbat
N
" Fson the malixk is
]= o. since
Indeguee [ol = Indeguee inolependent
SY
0.
foba, hanaly
Indeqei[ 3 , indieetes hat fe 3 depends en 3
VT
0,1& Q.
Incegoee lA]= 1, ndicotes tat
3, indicotes ttat jot 5
5 depends on
Indeqnee (3] =
&, 3 and 4.
.IN
3
foen cot adjarency ralbux 3
O3
0, I 3, 4
0,4
C 5
N
1, 40 2,3
SY
3
J, 4,0, 2 3, 5
I, 4, 0, 3
5
I, A, 0, &, 3,5
U
VT
Topologieal
oblained úe ’ l , 4 0, Q, 3, 5
Topdogteal 8equence
ZndegeLjl+ sun
.IN
end
C
N
SY
q(undegaee s]==0)
U
VT
end
wes[LoP]
Add u o glu¡n Vec T
o ench Vetex Vadj orent o u
derement
end le
hoteT Studied smart, not hard — thanks to [Link]
Many dmpet ant potlerns seoyve findlng an dement ndt, a
inetut elre.
lypicalls, suet ptlome atee in eiaalin ttat wolves
Comlinaloial objesta 2uch as pounulalin, conhinalion and
Bubsets ee a given eet.
" Exhoulire a cmch 2s Bimply a boute ktee appRoach o
Combin&ial pueklme.
t Bugg ets qenenanq each and eresy elenment the puctlan'a
domon seleeting dth2 .em bat ealiely ae e conaleaint.
aund then indlhg
.IN
a deszed elenet.
inpotant poulema, C
palesnan potlem
N
knapaak potlem
SY
.IN
t Ppblen incesses
apidly
Eagtegt waj lo th an exact auion to. T9p t lo cenpute te
C
COst le lous Cn dtesunine dthe lous hoith te menimun
COAt. Thee metod is coclled exhawalive seoenial aeseh and
N
uses boute toree opptoach.
SY
U
aue
e epse2ented P. args and #he diatnce belioeen vasiga
VT
30
6 9
P
p s p
P
P A
P oat =
.IN
P C
ps s p Coat =15)
N
SY
a’c’ba
6satea a-D
Ih qereal, le en'ios
n'ies unbee ee esutes = n-)l
.IN
i.e,P(n) = n-))
So, Eme omplex gdo given by t()eo (n) C
Knapzack Packlem :
N
Deltnlion - Given n'item kenon welghts ,, [Link] and
SY
Item- 4 -
3
40
5 Q5
7+3 = 10 4&+1=54
.IN
1 + 5 = 37
{a,43 3+5=8
3, 47 |A+5=9 40+ 5 = 65
), , 3} 7+3+4 =14
C
Not feceible, 14>ID
Net feasible, I5>10
N
7+3+5= 15
1, 3, 43 7+4+5=)6 Net feoeible, 16.
16>10
SY
^a,3, 4 3+4t5= 12
i),2,3, 43 7+3+4+5 = 19 Net feaible, 19 >10
U
Arnalypis -
cun element et ie , tbe exhauelive
. The nunbe e tsete
Aecuhlecds o a Eme etcienc
i.e, )e ()