0 ratings0% found this document useful (0 votes) 23 views32 pagesUnit 3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
__Mopue=3_
“Dudbetx chain _mubtipliication +
x B S
r 4 f
L J C
4X3 SxX3
ar
Total number ef milttbiicattens =
PXYUX®
= SX4X3
= 60
AX Aa X A3
RX 3x4 EXD {
do a; do, dz dy dz
(Aix Ra) KA A, XCA2% AZ)
Bx3 8x4 4X2, (2x3) X ['C3x4) xc4x2)
Qx3x4 9 o
Sage 10 4 on BX4K2= 24
e Foxmutla to Find paxanthesis in mobuices
er Al(n-t) C—
Wy
n= no. of matricesYou ose Qpiren Huwe mocbuices 2 A1sA2, AR
SO we fraue to Posentheatses trem the +h¥ee!
matrices +
a(n-l) _ Where,
Posimuta to : Cie . n= no of
kind _pasanthesis 4 matieix
Ay Aa GE)
8X3 3x4 KR”
- do di od da dp dg
(Ar-A2) A3 Al (Aa: Aa)
Ax 3x4 O 3xe are
2x3xK45 24 0 3K4x22 24
&x4a K 4X2 &x3 8x2
Axor 2216 Ax3x2 212
€Ci2) + CC3,3) +doxdax d3 CCUIIE CCHS $ dee ding
ie
Cyl = mn VCD + cLeti ja + di, 4 kH FH]
fepes
J
wee = eeePage No,
Date
, Nes a) n= no of motux
? Le (n-s
y
: Qurs! Ar x Az xX Asx Aa
; —_ 3x2 axt 4x3 QXS
r do d, dy da 5 dadg da da
Clinj d= mum LClKI+ Clat jd tdi.) x dy xdre
eC J
kK
|
i
1 \2
Sea
| p
ww
I
a
3
4
Keil pom LO1OF 3x axe
= rin faa
= a4
C(413) = pun Je (2:2) 4+ Cla3a} + dy xde xdg ¥
Led, ft3 5 ke2 t
Min {Ot OF 2X4X9
= 16
C[B.4] = min {CC353) + CL 47 + da xds x%5
£235 JE 4) K23
nen fo+0 + 4X 2x55
z 403]
1 fe3
Page No,
Date J
wif CCID FCE23) 4 do xd) eds
(129 46(3)3) + clo xd Xda
nuh $3X2x2 2
a OF 9K4K2
22
| mun | a8
| [40 J
=as
Clare] "= min [cls2) 4 C4) ds x daxda
Jad, fe 4. | casa) +c [4.4] +d) xdaxda.
k= 253 :
_= min [odsor axénef
i [let O+ axaxs
= min { 8 2
Use J
236 _
CO = mn Pel] + C247 + doxdixds 7
feb pee CLis2J + C0394) +dox de xd4
Kel, 293
cli3) * Cl4s43 + do XdaXdq
wm (0 436 + axaxe 7)
fat ado +3xaxe |
(48 +o + axaxs J
min [66
|_|
LY
= 38Page No.
| Date
| J
Tn this we creck [isd] condition in K matwin -
In K matuin block [194] use check Value econ
to that wu sepexote Hrs
poe £1 3
ee
TCR) 44
Al gositlm Fou Posxenthesis
Pscimt: ~ Optimal pasums C53 inj)
[PoP]
tg tj
Him _pxint “ AF”
else print "C"
Pourk - obtimal- paxaens
>] |B Joo] |e
Paint = eptinwat parons
paint")Page No.
(Date
We hae gist He Seeutes £4; 109 85 129 8%
Al Aa A3 Ag As
4xXlo lox3.. BXI2, 18X20 ROXF
clo ay dn da te dg dy dy, 7
mij] = mm f mei,k] + MCkt+ sf) + dy Xd Xd
teksey
mun Cis 2) = min JS mot] + ml2s!) + do Xd: xdy
jkel ba :
= Otlo¢ 4xlox3
= Ido
minL23) = min J ML2:2) 4 m(33] +d xdaXh
k22 l
= Ot OF/0 X3XI2
= 360
ml34) = min J m(33) + L454) + da Xda Xda}
-
= otoOt3Xl2xaov
= 7120
m [495] = mon § mC4s4) + mC] + dgxdyx
. “dsef
ee
Pan fail) 4 C203) 9 do Fd a F
nin (12) + ME3s3)4 dixdaxds &
ef
= O+ 360 4+ 4Xlox)2 =
= l2o40 4 4X3 XI2 cs
J 340] ef
[act J a
= aot
A S|
min £94) = mun) m(22) +m (3,4) tdixdaxda ) &
k=23 [mla3) +m (09) +dixdaxdg( ©
: -
« J OF 720+ [0X3 X20 Se
Wan [B00 o F1ORKIAx ao e
” e
= 1 13808 e
[aréoJ S$
= 1380 =
-
m(3:5] = min f mC3/3) tmlOs SJ r+ daxdjad
kK23,4 0314) + M055] + dandgxds /™
: ; e€
© t168O0+3xK12% 27
TQo +04 sxdoxe [
y 9322
Uso J
rd = II40
AHMED WADPage No.
(Date J
mun (14) = mb) tmly4] + doxdxde
kel203 mCh2) tml304) + do xd2 Kd¢
Um 0374+ (4,4) + doxdsxd+ |
(0 + 1380 + 4x!ox 20
{ 120 + T2044 x3 xa0
(ace + 0 + axxo
¢ = Jf alac 7
Ga | Jo80 KE 2
4 aa’ J
= 108.0- 10): *#
nun [ais) = (-me[22] + m(3,5) Tdi xdards |
k= 8,38,4 { m (23) + M045) tdi Kd3xds
| m (234) ¢ml[55) + dixdgxds
Cotli4o +/0x3x% 7
]i 36041680 410 xjax% |
(13ae +0 + lo xdox }
1350?
48380 \ ke2
diac |
Wee
1350
mm (U5) = (MIMI +ml2; 5) t+ doxdixds
K=1920394¢ mena) +035) + doxdaxds
mrad +mlhs) + doxdaxds
MEb4+ mots ¢ doxdt ede1630) |
1344
| das 0)
lo 4)
i
Kea 1344
Fos Posemntheara :
(a Az) (As nal) As
9 | Convex Hull -Puoblern :
ald tt onl al cel el an! nl
@leuexy Lint Seamont oluaurm betuwen any tuo |
botvs braids the fyi Aes Cndinely soicle |
CS
fa By
{e
tua_polyaon “Sonneited by Hee ore beg pint
Hot Aber not cuss tut polygon: Q
Given a Set m ‘§’ & tpeints sy the plone
S= § Pps Pas --. bn)
the COnuex Wud dy Hee Smaak Cornu
Polygon P fer whith each pontitn S lu ther[oa] IT
| en the boun davy JOk Pon dn ats Aniteruons
Pxoass to find Conduce Mbt :
Posctiken of point unto Awo half / x) and Xx Or
X_Co- oxdunate:
Thx es Empty One Roh
Oey 1, 6 ent thin Upper hull
ds Stnapely Qa Dina. uci tn Endl peunts P, and P,
Tk Xia not eonty the _algosiitnm: 4thd Prax whith
is puctloat decor? P, and Pry ©
This algo iclintté {ies QU the points of %, tude gs
F a: r *
tuo axe Pmay tren we conaiolesced
Pmax He pout trtaich maces sagan Conghe
with PL ‘Point -
f Bmax
Craax
! EZ Ais TNFa Uphor
fy i het <=
a ae (Come
~ AY s hy Ud ye
» Ping louse 7
Pray
Py pe i
L___ > YOR
: Fe ts-KNAPSACK PROBLEM ¢
[In his psoblem ue wort Jo pack 'n Him @
Ln your dang ec 2) Noni «
| Suey, ‘tom ty Chood ed with [value (v;) and
Wueight (/)
© | Twe Ayes Gt Knap sae bso blém J
1:| Frnckisral @ Been aun gisles knapsack problem
"| 20 dud One Kmopsock ps0 blem
1
AVAV
Foactenal Knapsock psoblem ! as
Faackon of tems tafen soto tam Mafing
@e@
pe
0! Gasrt_'4! “Kno pros
zyo'O'amd ene't' knapsaxrk fscoblem «
+ ———= €
Each thom is taken -o% not taken » id
Comnot stoke a {uackenal amount of an ©
em and Can't take an item mose than enue
@
boast ok tre momolt omg tan ™
Satue the Subproblems rising afer dine ©
chou ts mode c Z_| The chotte made b be | the ie qpecdy a aug y OAL Hy rp? oP Pad
| olefoorrd the chord’ 50 fer “tee Cannot
cleo 6 __ ary dustitny choliz ox On the
| Soltttom +o Sco prtoblerng «
Comaider § its aleng tutin thedcy swiptchine
wea And valuss + FS lowing tye Selatton to
ak tpeckionet Knap sace Problem.
I= <3), 42513, 14, Is>
2 W = <5S> lo, 20,30; dod
Vi= 30980) 100. Vo»1$0?
Cabauity of Knapsack W=60.- Taking valuc
‘ i) : . { Py WiTtor
inary the Pool an decay opeclore
[, cDieme wees (wi) Vowel) — Proper i
ay 5 30 6
13 ao loo 5
is 40 l60 +
a4 30 qo 3
I, ap) ito Qo pe 2s bee.
Novo tell the Khapsock according to He tirariy
@ value Of CPI)© Fut Uc Choose fem q whos
them choose tem 13 Whose wag di 0. |
Now die _totat wag ath Knap sake i, :
(= Stag= as
60+ -25: 35 Keak Uwighh +n :
Knap sack :
Now, He next em ts whose Cuetigdt fo!
Uke Wwarit only 3S +S61 ue Choose fection:
poxt of Is. ‘
Frockiono® pant - 35 xl6o =149 /—
of Is fe
Total Value ok = Bo +100 + 140.
“knapsack alg
= a10 :
Find He Seluk@n to fucceck’orn Knap sock
beoblem a Knepsack Ww=50+ Find thes
[Ca hems | wi (untgut) [vr (volen |
I [ lo 60 |
eae
Taking Value of uuulghet Aation
Oo
Piz yy [we
“
Memo Wega | o
i lo Go al
Ta ao + Joo \ 5:
iz 30 l20 i:quran ng arta cake, teal decutaatiy opeler Gta
[pe “piv
Lo
Demo aS Uaioe rsa eae [3
xy 6o 6 132 30
Ze 7 loo cS. Ias4o
33 30 1a0 | 4 I)=le
Li jot |
1
w:Sso
Novo cu ths. Knapsock accoroi'ng to tre
decenang voli of Pre g
Prick ume choose tiem Li whose ueight 4 lo
+m; Choose £tem I2 whose tee ght 420
Now, tre _totok uetart of Knapsack w :
fo+ 20 =30
Hat | Uuegnk = Sea73e = Ae
Now), the choo ittm I3 Whose weight 5 B30
but ue “wont Orly. 2050 ue cnrooce fencttonet
pase of 13
Fuackenet pot: go. x20
Gt 13 30
=80
Totel value Of :60t+looF+ B80
knapsack is =Q4o-Po/t_ Kya psack —Pereblen t
Po $4,255.68
w= 9 2,3,.45% ' 7
W=8
n=4
= (Rw)
ae) Tart
sa pth 2It
s'= 3 Go), Chay 4
Ss =} (253) 53:5) §
} Coe) U2) > (253), Cast
Sve 5 054), C66) CH) Ca, EA) t
value ex eacding &
The WARE
> = }lor0), C152), (253), 9505.4) > Gb)s Galt
Si3 =} C625) Cy 4) 9 (88), CUNO D> (7), Ciao Dy
(13;12) 2
Sq =f 0,0) 5 2), C43), s5)5 bs a), Ey,
G6) 5 CHV, (88)? oleme
Fate
| s*= FG.) 2s 8), SH, HDDs
C66), CHF, C88) §[Page No
Date
»
b
¥
r-
y
,
Iq choose
(3r6 58-S)1= C23)
2.3 €s*
23 —¢ s!
Whence Choose I
(Q-2) s(3-3))=(00)
Ty) 32 ta 014
ot oo
Ee
2
[Ere
S= F030) 3
S®= {C2)
Sys:
i= J (23)s Caos) }
DS s* = F000) of tr) (233) 1035) 4
Sie F (ny), (69 C499) C49) 6
x
wo S2= Soyo), Ur2)s (233), (395) 5656) F
x
(66) ES,
(yb) FS2 DB rs
(2) ES pe
Clr) F So tspPage No.
(Date J
MINIMUM SPANNING see
use Cat it a sbanni Tian gy Spams tha gape
Thexe ase tuo allqosd iow {oh Soluing a) miniinten
Spanning tee py
> > Kiuasiceal algorithro
= Pxim's algaxttho
Both algo suttne’ ane greedy ag Sscitinns * each wep of
agonitara Malate One Samenok
sed ese aaa ee
Tae_quttdy sig adwocadis miofing. the choice
thats Bost ot fet memorct:
KRUSHKAL -ALGORITH M
MST—> Kyurshfal Co,w)
lw |r je
loo lalala
A=
Fox each Usdax VE VIG]
Make - Sat Cv)
sot ne edges of ECG) into nen- deouasing
osecose bay, wisp Wl e
Fos cock edge CU) € Ea)
ik find sot co) # find set cv)
Az Av {u,ev§i
unten Cu.)
setwon ACb») | @rb)] Covad} Card) | dye) (ere) |
3 4 q 3 |
2
O=-O A> {Cbd}
a] B+ 10Gb) Coo dF
V_{b =O
@_o
3 A> [lab] Cd{o dF
ay
7S
uw
@ Oa A Plax») Cb10) (Od) Cede)
af & © ratrirum spanning toe
= Utigne > 12 g
Find sek (c) = find set (2)
S20) Can't perform Uaién@eole@nfer | a4
La | fe fi 14 |
Ae
OO) AS {mgs
U Vv
uv
Ze KOA A> {hoa Cqr4)d
z
Vv
é
G Dae © » AA {ho
v ee
© O—-9-6—
a o_o
ap ,
ref A> ]Chs9) CHF) LOW Coe,
UPage Wo
Data |
A JP), 29),
nas APO}
) clue_to -Heus_its
© (Ov made A tipebes orf
a (Er Tq 00a ‘pair ales
iY
\G—S)
Cisg) Find set ci) = Find Se @)
so Can't porto wm Urn On
7 Crh) fend Seb (1) c Fendl set Cn)
$0 Can't pedo vm iain,
®
6 OO
A FcmredCive) Cord),
Cb) 4 @99 C39)
orate
(® asI
b »
: e n> 4(Ar8) CBO (01 0)
Ft (et) Oi ade
ro 949 ae
- EE
y
r
mr |
(0) [Gsh) Find Sek (a> Find set6n)
So Can't perform Umion
yyy
(f) COB Pujrd musts Cos
Pe & 2 g ri 7 -
= A> (CAB) Gis
—- Cd) 8)
n ) 2 2 2
: & o (crf) » Goes
: 5
—w GH Find Sek C@) = find suk @)
‘ 50) Com porkore Uniden
‘ = find st Ch)
By (yh) find Set Co? ;
oO so) Can't porkowm Unt Om
pind St (4) = find set (4)
$0, Can't yr Unt on+
Pager ot oh
rs 7 Se
4wegqeée = t24+24+ 444484447
g = Bt
Cb20),(Cod), €d@), CesT I,(E54), Ch>3),
C914)
Ouse tmblementotien of krushpak okgon' tim,
He Like He calgosercthm +o COmpite Con nected
ecompenents: 7
oprration fone Set Cu) sutusns A xapscosrntets've
Chanmrent deer Hie set that COntacn U> Thus we
(an Ackeimene whether tio uerctics and uv belon
+0 He same Bue by deateng whether. gcho Sok W
eqyual fund serv 7
A CA»),
|
2 | PRIM'S ALGORITHM
MST ~ Poms COts Ws 30
: Git _qvaph
Fox each Vevl@ J Wr ecgieé
ao Cul — Ot starting yore
PI
Luy = nit A parenty
, 5
eC
ra
ros
rg
;
Key [ng - 0
t
Qe V(G)
do UW = Extract -min(Q)
Ltopcke Q@# g — —
for Cach VE 2
VE Q Eu Cuvie key Cv)
RtvjeX
Key Cv] © & Curvy
= fas bad
Qe ex back = un CO)
wlanot / inte 2
wlan e / =wlarcj= 6° kuy (6) = 2
Q= food?
Sip
2
C — Extnact min |
Wwlesbd= 1 key CbI= pe | WlOdI= 38 Kychne
kuylb) > wee |
T
(SS
G= {body :
b & Extbaut min
WC asb) = F Keay Cadzo fracas 2 kyoPage No. ———
Dale |
= tdj { :
d < Extract mn O
sO (By pag =
Alle = ¥ ofettete
o @
S cae ;
axe SINGLE SouRCE SHORTesT PATH PROBLEM
—| {itis vt AegoRiT) —
t_temaint offending. the Shortest path beturon
a qpusmn lester 'V aU other uscticas dn the
Gieeph
Setution fos Axnght So usuce showeat pot
psoblem -
Pecim's De ykabtsa
algaxitean o
up fslatia ta fund Hae shot
pssmn's ancl Qininuim Spinning te04 (rs7)
Ama __Umel rectal gacfel but _pru'ns ory 40 9k
én _undiaicta gkaple
Puim's algo cas hondle SY canal cobb
but olijikhntea may tail Oc: combuk
emistDyrkatora C6114 9)
® }
| —
4: | Tritia ise - single Souve (6155) a
2] se - g : ee
3.| Oe va) - Ty
Se ere a
RCD MMilte vesicle enn CO) nan
S& sufuy ay
41 for each umebtx ve Adj Cv)
B:| Relax CUsVs WwW)
@ | Initialise - Stra Sounte (G1+$)
I] Fox each usutix Ve Vad
2:|.do dWwje ow
3: nO <— NU
40 dCs] <0
e | Relax Cus vi w)
(| ak dv] > dfu) + wlo.v)
2: | ton dfv)] edtvl +wv,v)
3 ACvjecu
6.
Ques | © OQ 2 skp ©
[pe :
a
oS aS CO. :
am t =
ok bes
OLE
= 5ea a
i ATS
52) 2
; A i Ns ad (A2= Bavdc
\
io ee WwlAB) = 6 wlA;C)= 3
ae extuact min (0)
a o+3 | wrote
oC be I c= °
SkbC) r
= Its
or oe
© $=. fay
b & extxoct men (Q)
ee BK,
: @sjodse3
ob veO) Seh Os by
Cee ; 3
— . -
O— © 2
SEL CH extearct mun (@)
: Ee Gt 3 > aa
Cah—__ ClO utr 10)
Ny o-conte
a G= feF
ee Sz farbrCsd3
skeb @) e << extrac nun (@) .
: @= 44 ND adjacent
S= $45 6)09 0 F
@|BELLMAN FORD ALGORITHM ;
> | Th hg cristo can_uoak On both negac' ae
re g ma 7
|_| 0. .
Naas:
e Bell manjord CGiws $)
|| tnitiobine - single-source CG»)
2-| do £1 to |v CGI) -!
4 | do Relax Cusv, 0) $
Ss: HX each edgs. Cu) e EL) Fox
6. oe ik dtv)®> dcuy+wevy) | xemoui:
Te} then | sutweun folse negative cycle"
8-
Sedu Tue
© Initialise - Single Source CG3)
Fos each vwokx eV(G)
2: do dtvyjeaw
3° ~*~ EVI — Na
4: ds) <0ioe Relax Cus) w)
ak doy > dtvl+ wav)
Hum Ad fv] —d Cu) + w (urv)
A fv) Hu
We
see
Ap Be ED DB BD De BC AC
Fos A l
deed > dlad+ weAsB) 4 a [c) > ACAIt wl+ fox B : #
dtc) >d (aj + w lb)
eee etadeeleeeteeeeeeea
dey © 7%
Geers Ae w fe)
Egg Poe cere eee!
dle) « 0
dldj > d(@J+ wlGdJ
o FEA EEEeE pte
deo} <3
* Fox O
fe d(B)> d[o} + wtd,8)
elie tl Folse
dlcJ > d(o)+ wlrse}
2 > i 45 Folae
—] Fou &
Jo> 4b + 33
fx 2
d(o} <-2