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

Gana Daa

Uploaded by

n200886
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Gana Daa

Uploaded by

n200886
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Unit-3

rsolnspace REEDY APPROACH


Gneaay(a, n)
Solatin= ; Complexty
fox (i=l to n)
sateettn
X- Select):
if(Feasible (x)
add(X, solton)

Tob Saynencng wth dealine :


CPU is
only caalable.
is nst alloued.
i) 4 unt is
Q-:- Bsute fosbeqied for any job
ce appach
CPU
Tobs
Dadline 2

Proft 260 300 200


300

Feasible sohhg 200

JD5(}, )
S00
400
3So 450

proft a> 550


i,Ja,sJ, 47
pouft:
(J,,T,I5} 125 ft: poMan
J) 3, s: optimal son: optimal
end the fmFil
me
lead wman axsay
is Size
of b)pooft
7 4 2
Maoumm
3
P 3 3 3
2D 80 P
2
2 paoft of
desarding
25 20 )5 ba oYdex
30 in
3 3 Deadine
3
l0posfft:
6 Max 80 Pofst
(s
Js Job
=5 Q-l:-
=)27 Poft
2
{II}{I,3),(i;)2) |103)-11o
(,),(.3), sanOptmal
2 D
24 30 12) 25
P
soFeasbl
ln e
2
2 3 Deadine
2
2
|2 30 22 24 P
I5 Prft
n6 Q-2)- J
n=4 6-2:
9Asange al jobs in decveasimg ovdex of poft ofmlyn) Greedy
) Take an
aiay of mamam doadline. Factorl.bpsak(we,.), ra.-j, w)
eghto
3)) stat Aim the ed of the fox i=l to n do
Cotan deadline qeatex than agay ovd seah fox ajob,
or egual to di usihg ivear Ali]-0;
ukile twergkte W
W,
4Repeat sd step-3 fox each slot do (-best 3enaing t em
beght +u)swthon
Al]F1;
fractonal knapt
)Ttemy Can be
ack probem
2) Acc t boken t small pasts. weght w;
poblem statemet: break:
i)n itemg ase there in 3 retn A Max Compleoty o(wlagn)
i) eigkt of ith the stuse.
iteng ws0 Q- n=1,W=l5
i)
b)
) Capaty of knaptack is w. obj2 obj! obj4 objs oj6
ob;
Since tema' canbe bo lwegit J

take ony afrahon ý;kenof jnto smallox pieceb 3

tth tem. sthiet way


3) Hence the olj 2 h-té
objetve (s mgximize A
3

Subject t constaint(*o,JW (*.) obj 4 h1

55.3
SPamong Tree
Comected
ree iff:
subqph S of a gaph
gsaph G
G s Sald to be
i) S shouldcontan all the vevtcer of G.
spo
) S should
cortn n-) edges if Gcontos n
veiticen Krchoff 4hearem
) Compute the adjaconcy mata.
O)choe into -'s alll! non digorad elemants

A:
37,changeo's alt to dingonal elemants
egualont deqves
Copute cofact of the meti

0-1
---0
A
-| - - |

4) 2

-
3

3 = /0-28
Diafoant Sets &kuskal's Aontni hshest sank
Lt is a qdup of Sets twhese no tem Can be in
one set (öj ind Sets) lo) (o) (0)

)Makeset
) hion A-fr41s6} Uhin (2,2)
3)ndet makesct(),..- akeset() Uni
Uniosnhio(6,s.))
Undn (s, 6) () (o)

Unim (3,7) (o)


()
(0) (o)

bepruertehe elo ) 3
fmdset (3) =| (o)
(1) 3)
-opexoons
n-elemends
Tme conpleity - Om)
kaukak Agohm
implmentcbn by trces (Chanby xonkard pcth, compega A- empty set; ol)
(o)
fos each Cu in )
Sot vnakeset Cu,);
(0) (o)
(o)
(o)
Ein inCreatng ordey
fos each(fava hé
(6) (o)
Sorted, lat E)
(o)
Add (u) to A;

etusn A;
9)
60
(I,2),- 10
30 (34) - 20
s
(I, 3) - 30 G 2.
(2,3) Y0
(3,4) - 5D
A-{2,s}
A-{(sds
(2,s)-60
(s)- 6o
Elye
20

Prm's Alqoxrthm
'A-{23,5,s A B
FF

r MsT PRTM(ueV[a] logv A 3+ 3loqV Adj veatces +Vis:ted


fox each G,w,x) A

A
N

5+4lgv
2. do keylu)0
logV
3 342lgv
TT(u]<NIL 3+0gv
4-keyl) <-o log 3+ logv
G. while Q0
do
ue-EXTRA CT TN(a) slg|
2E+Elogý
fis each UEAdjlu
do if oeQ and
then T(v]<uw(uw)<key (o)
Keylv)wuo becapage key
Tine Complety oy
ool-yrt. o(2E)4'o (alyg
=o(cme)logv)
Nae:
AsioQ-Mttx opt)Prnaple
omality of
A{B<) =50042S0+2s=
J000
A(8c) +(sxsXlo)
(o*s*s
50042s0(5xi0x
1osxi Chan
(CD)
(AB) Memoizaton
Multplaton
Giexio
(sx5 Askio
5
02so
SXS) +
(lose/r Cioxs
xio).- Bogmmsng
Dyromc
,

SDo#2SO Dsxs 3
Find
(As)
(co)
(5Xi0x/0sxlo
s50+(3Xsxjo) Asve Aß
- the
minno.
t
A(SCD)(ABc) D ABCD
SDoF20+(s
xsxs)
(oKS

Cloxs
is k<j
Dynomic pxogramyning approach:
us asswe that he toux stagts at
erter 1
ToRS )Each tux Consnts of onedye <4,k> for some
MNRe4)- win
7S0
25D l000 apart trom vortex k t 1, gong tough al! keV-{i} and.
T vertexin V-{k}
exactly one
LMMe3)+MMR(49+ Is -875
MMR(2,4)= JMMR(2,2)+ MMR (34)+.500
Vmin
Problem formulation:
et gli, s)- length of shortest
vertex in path from node ii going
loxs (44)+.2s0 S and
temnation at 1. though all
MMR{34)
S
-

MMR (2,3) = min manmme(B,3)+MMR(4)t250 fos igs 2<ik<n


<tglk,v-qux3)}
MMA (2)= miMe(3,2)+mR (33) +500 gli, s)-min{cy+g(us-c9))
monMme () + MMR(2,2) +500 1
1 2
3 4
SDo 70ns jes

MA(\3)z Minmge(2,3)+.250
MMR(3)= 500
\mmai2) +mma (5,3)+.250 lo*s
2

0. 250
6
5
13
3

(A(eojo 25

Tzavel
t lG{v,
ingE) Salbeespaosson Prsbsleom 2
tg(2,(34):
g -35
directed fmph with Cost
- 3 Optimal tous cost
toua path
2) Tous of Cieph
eveny vertex inG'a |2-3-1
1.

G: dieted ynole. cycle thet te )3

3) The cot of 13

TSP is the. touxs sum of. the weyt of edges on tss


+2(523)-1s
minimm cost toux g(4A)=.min S4t.9()
thus a shortest
verter of pth p
) f k is not an itexmelate intemssdate veteer nthest
path frm i to toth all itof oth all
{yo k-l} is adso a shovtest pott fo ,CK)
Intesmedte vesticer n the set i2, k} dij
(K) (K-)
di..
i) it k is an thtemediate vetex off pth p then we can
dacompare P mto
P
Sive solctsn of all par
Recwssive shstert path
n.2^ subpxobleoms
o(n) fn tmes n-(n2") Recussve fonbton
let o be the weight of a shortest
Floyd Warhal's algsthny fos hih all te:malate. patt fm vestex itoj
dFoyd Waxehall algatm is the vextees dre the set {,k}
sohe the shortest path bw anycnamu progiytng. ppronch to
2)Tn this tuo vertcer on á dreted
that nono negha wegt gles ae gryhá
we aswme that
3) Tt nin
preent Computing the shostest potthi
Stucte of thartet pacth Weassume that the vex'es ase
the mput numbesed l, 2,.... . N) Sothat
)t consdox intermedite vestes is a
[w mn
foaph epegendngthe
ofa, an nvexten direcfed edge weryhte of
ndemedigte-vartex
estex p af a sirmple path shortest path, whese an Jsagh ary)"re (w) W hen
Pothex thanthan Vio Ve iej f-fu... is the Wi Jthe oeigtt of direted dyeliy s) #
anvertex he set ijand (Gj)eE
2 Suppose
Subset vert,...
ices kofofGase
vevto Some k. consider a
of
who se mtexme ditevetices
feV,contidex ál
let pP bebe aa n'mumverstes ate all dsouo -fompathsl tfsomtl k are
weot path
path among them.
FLDYD_wARSHALL (W) ton a 2 3
) n=.Ws 2 L IL lL 2
3 wIL NIL

NIL wIL

s) fox kel ton


2

4) et p'* (dbe a new minl


s)
nn matt mm (D, D+D)
fox il to n 2 5 -5 O -2/
3) fox j=) to n sloo 2 3 4

2 NL NIL NEL 2 2

SLNIL NIL NIL SNIy


onstuting the shostest path: 3
-
2 1

when kep: TGIL NIL 2 wIL 2

1
2 -S
NL AL S
6OJ

when ke1:r 4 -4 2
(k-1) NIL NL NIL 2
NIL NIL 2
-S 3
Loo NIL NL L

3 - 4 -4| .(4)
2
-

2
4 3 NIL 2 I
2 -) -s 0 -

S NIL
2 4
NL 3 5
3 0
2
3
NIL 2
2 -S

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy