DAA-Module 3 (Part 1) - S Mercy
DAA-Module 3 (Part 1) - S Mercy
Module- 3
- StStraightfovumd desgntechrique
Greod rmethod
Genenal nedhod
o oblan a subset that satke
Fov h 'puts, Yesuire l
Some constraints
the gn»tvasnt calleol a
&ubse thot saBske
Bny
eable solus'on that eithe maximize ov
Find a
eoible 80lukon
s0lukon dees b caltd
unmiz gn. a okjeciue fn. A eas:ble
Opkmal solukon.
hat one Can deuise an
The heely methoel suggeats
that wore in Stages, consiolering One I/p at
a
goithm
'ne
A each staçe a dectsion ?s made Yegardtrg whethe, a
solukon. Done by consdering the
PavHcula I Ip is in an
opmal
n Ovden. datemined by Some selaetien prOcedure
Ip s an
Othevwte it is acloed
SelecHon proceduno baso on A0me opkm3aon meastge
Subset poadism
poBelect
select (a), Sebeb an p kom al) arrereest
f Seastble (Boluhorn x) dhar aastbe fs a bolev alrd
Soluhon= union (80luken ) ; Tunetitn dhat dotems
opima mO pattecs
Coin chnge pme 3-
A chld bnys Canely Valued ot los han D 100 arcd
(Change
eicaæos STrupees)
upe
The Ehard Pank selockeol is a 10 Rupees, bhen a
adeleo » he chang.
The ghccody metiood has inhutkve ppeas in dhat whj),
he inhuihon
Conahnuct he change hy wing a Rbategm hol
d w dhe
tello us shodd reult dhe ewent (ov at leart close
euvert ro Rupees ov Cot behg 9ven Out
Ove dhal Hre ecoly algodtn olehbeon, inolao great
Chan cerd dhe tewet nam e
Knapsack ppbl em ) cot
Capath m
IP nackon:, Og x:<I
a
objectiPs placeed
in Be
krapsack, bhen e prokt Pra eon
s
moxtmized
weight dhe obyecks chosen Bhould not exceed bhe
capociy knapsack
objec ae ahanges in oleerwasta 0volon prJw
m a0
1 39 S
S 39
P 1S as
w
16 18
X=I oY YC TC C - w r X
ObectC) wt Pi
*Pi
a0-IS1 = S
IS
S- lo O S= o
a S 0S O.SXIS7.5
3 18 as
Frachon (, a *z) =
(10S o)
(0 0s)
Prot ah+ 7-s 31 S
.obtain dhe Ophmal 8olukon br he
krapsack prubem us
Prg
honsluy metood
P Pa Pa 2
(30 o I23
3s) i 18 IS 10
P 30 Pr 30 2r 18
w
as
6 3S M1S
?i lo S Is 7 b 18 3
3S 4o 30
w lo as
Obgect t wi P = | or YC PRE
wi pi
3s 3S 4o-/0 30
2 as
30-aS =S
3 30
S03S
a
S S-S 0
te Fob 1s
Completeod hy r oleodine
To Compete a job Ore has h pmes &e job on a
mlc hv One unit Bme
Only one machine s ava'lake br proces jos
A
at ble 8oluton hv dhe pmbem a ubset T 3
os Buch that earh job in tho Subset can be
COrpletod by
deadlhe.
The Value enrble solukon I dhe &um te
Solve the
hllow ob c_uencing problem (mau'mizms
hllowna the
poktg
POK
Complekng johs bejove b-etY oledlines) ustng qraeol
alonthm
N Nojoks= H
P PA Pa
deadlene
CYeole an
aau i c h Abre,
the jobs
3
P
TXE job p Insevt i t al inax
Pa P
Next job s
Pa wih dleodlne a. But amay i3
alroas
Occupred Hece discand P3
Solukon an pnceeo
39
3 s opimal Only jobl anol
ar he value is 1a7.
Thee jobs mu be proceseod tn he Ovole job k pollaweod
value
eaile solukon pvaces4ueee
(1a) ,
C3) 3 oY 9,)
a pmdso lasn
1,4)
(2.3) 2,3 aS
3.4) 43 42
(1) 100
(a
(3 S
4)
Che
reulkrg T 's a easble solubson.
Constole
Onstlenjobs t non incveanfng Oolar c dhe
e Pis
pis
Hgh Aovel decypkom job sequenctng algovid
eody ph ( int dl), set I, int n)
3'seAt q, jphs l het con le amp lebe by
dhaleodlina
or (in i
- 2; i<on; itt)
all johs in
Jus*} can be
completrd by thetr oleodlire)
33
The Gbove algoidhm Corshnucts an
epkma Ael 2
jobs tha can be proces sed by dheir due ime
In job Ehere
se_uencng a 2 poKsTble parame ters
in term cwhrch i
comdexty Can be measwned
wse n
-no johs
S-
ro jobs incluoleol in dhe siluson J
all johs in
JuSi} can be comperd hy thetY oleodire)
33
The above algoidhm conshucts an
opkmal Ael 3 2
obs thab can be pvDces sed by dheir due ime
In
n job sequencing there au 2 possible parame ters
dlo-3lo)=o , ni Hali'z
incuole jo
int e=l'
fov (int i =2; i
tenit+)
constolen jabs
non'ncveoning DYoler pli). Finol posikon bri
and cheek eoibikhy cinseaon.
in Y-k,
ohle
((d[1) >d(n) (a[í))
Y--
fnse. fnto 1 |
l» () slop 1 d
Yen (kD)
2 nokre to Jeops
AEE
hS ,
(P. a Ps Ph Ps) =
(20,1S, lo. S, D and
l(d. op ds d, ds)
*
(2, 3,1,3,3)
3
P ao Slo S
di 3 33
Select 1=1, P; >O , di- a
Selecli,P:Is,d
Job I and a widh pokE a0 4S =3
chongt
Selr i H Prs ,diz 3
34
with pm kt o tiS+S = 40
Tobs I and
Oven
OpHrnal &olukon 5.3
otal prRt =
20 4 IS + S=o
a)
To,Da) tanro t Rt, geet
3
.33 Lo3)a) 35
Pim'S olaovdhm
atven n
points, Connect bhem tn be cheapest poseible wo
So hat bhere be padh. bet
coln a
evey paiy points
Poins- Veitre aph 3a
Possidle Con neehon-gnaph's eolga
Connechon Cosk eolg uwezhts-
Spanning breet
pahnig rea a Conhecteol gaph is Connected acycbe
Saanaph that conains all bhe vevkce be ghaph
A n a a qsaph Ps a Skgaph ih-ch ?s basiay a hree
Minf C n:n Vebre, s, a containis he ctevsk.
MST
MST CG weightrd connecked Gsaph s i& Spanning ree
Sum
bhethe ueht on all i6 esge
MST
po bem Ps the
pmblem 2 1indins a minimum
Sponning bre bv a gn weisheo connet trd aph
3
In eha totve ohstacles
Beav ch appmath ,
nospannig kes qows oxponer'alid he gaph Aiz
íteakoe
Otak n0 4 tteakon is n-I when n is dha no veyhres
Bthafph
The tre Gennotrd dhe als is obtained as he et
ep wred the kee expanston
ghaph will have ony one minimm spanning hee f ane
Ondes f &he
the weshk asociatel torth all the
eolke in he qnaph ane
dsknct
In cane d HST doe not malu complete Sense.
Pppi cobions
(a So
So &'o
So
3 4lo o O 30
So do30
Consden Source =o oY 2
Take Souce = 0
dlo o O 6 O
dl 6o60 6o 4 A PL3=o O
dla) 1o LD PLa)= o O
d33- PL3) o O
o 30 30 30 PL43 o O S
dlsj So 50 SD SD PLS)=o
S V- S
dlvJ= min( dtU), costlustva) P£vJ= u udlul upluo
I,2.3, 4.S
0,a 3,4.S dli3 - 6o
dl3)=% PLSJ 2 S.So Sa
dls) So
0.3,5 ,34 dl 6o Pl3)-S A30 AS
d[3) Po PLA)-S
dL4 30
O,2. S, 3 dt zho PL-4
0,2,SH3
roeec, hy sdykrs
Coa h d be daleen &r na n s Gru
Spanningbe bhained by(,0) (S,a) (4is) (1,4) (3,1)
Iree Vevkce»
Remaining vevkces
al--) bCa 3) Cl-,6) d(-,) elai6) fla.S
elfia) d (f.s)
dCs)
nemes ma vete
dtil-wl souncr, ) (
Pl)Bouvce
Fird msT
S[80ue)
Sum o e)
Scec an
eolg wrdth leak cost
Add cost selscted edgs to get botal cost e MST
1eY ewenn ueV-s de
if wlu, )<dl))
dlv) luw)
PtEu
erd if erd ir erd
hor
lea»t cast nom bhe cost askjar
3-
O Obtain an eolge otth
mab
min99
Source -0,
tov i-o lo n-I do
to j- o b n-i do
min ali)Lj)
Souve fe i
S
endif
Cno bv
S
TntHalzahon o 1nd min 87
fov i-p h n-i do
St:) eo
dliewl80wnce,
PiDEBource 3
Firod msT
S[80uce)
Sum 0 (13
or ie o n d
aold u b s
Seect an eol wrtn leamk cest
Hlg.
Olval)
Apends mest d re in sekcky dhe edye wrh min lengdh- Hoa he or
Kruskas's alprithm
Alwa yels an opimal olukon
MST or a wethtd Connecbed qeaph h(V,E) as an
edee ohevcose.
Each Connecr Comporen a Bubaph gentabedl hy
u ta' s alg ts a kee bco t hao ho
cycb-
Csua's ala han chel whe tme bold'on 4 he neet edje h e
create
olneodly hpked would a cu
3 S
bc
3
ab3
dfs
un onx, -
S
malke Set : ) = S3a3 33 S43 2r} 163
uan(1,). uron ( S.a ) 5 ,4) s2) $3313
=
union ( S) ardd 6
urion (3.6)» 5 i,4s2} S363
S4,8,63
O
Find the MST ing kukal's algosdhim
16
Eda
Eola cost dektrd tndlo) olp union(ij )
edg J-hdcv) (u,)
(u)
o 2 3 4S 8
6-3 6,T
67 O a 3 A 5 668
8 3.8 8 O 2 3 4s 6
S S6 S6 sI6
-1
O 2 3 s s 62
o O 3 S S 6
2-5 8
S O2 3 S
2.S
6-8 1 6,8 ,
discad O 3 a S
a-3 2,3 ,3 a3
4-8 3.8 , d'sad a4 aS6
0-4 1 6,7 b.4
-a 16
3-4 18 d'sad 4 S
3 6 ,4 34
4-S
- 3
3-S
18
16
Cosk ST = J4
3-
Algovdhm
Count-o nihal no edge,
keo poin fvct selecledl edg T
Sum-0
Inihal cost HST
br id v n elo CYrate a
wre,t wrh h
erhte
Ponentli) ei
Fnd hr
wkle ( (
Coumt n-) and (E+¢))
Seeet an
edge (u) widh least cosl
ird (uipanenl ) ind be oot ur he veler u
j inl v. pavent )
f roob au d'tleent select the edge lu iu)
as he eo MST
)
Count ++
Iup date no edge selecked fov HST
Sum-Bum+tostlu,) pdoe be cost MS7
Union (iipavent ) )
end tf menge a he wh rot
iand j
Pnd wlse
count! na)
Spanning ha does hok extsk
Yen
end
Spanning he 1s 6
toY (ie obn-2)do
oite (iLo), tfrya) 3
end hr
whle cost e
spanning hee, Aunm)
Phro's alsovidhm
Tov obtainng Hst by SelocHng dhe adjacnte v ho
Time Complexihi
So o(E Cos E4 E)
Dtkstva's algorthon
fov a
roY a gn Vevbex calle the s0uvce ina werghted
verkce in ovole
Difisha's a
al inol the shrtest patha bo a aph's
ndhetr osstarce nom a n: 80mee
tvs irols bhe Bhovtest pah om bhe sourre
h a vevtex. nearo bo ?, then ba Secorol neanesl and So on.
Apd mS euk in drining a ow cost Coryate nehworle
20
o 15 1 4S
do 35
3 10
30
ao
S
Stat w Hh sowre nooo S
Jn' al t e nce
dlo) ob 49
dL o
dla) o
29
dla)a4
39 34 3H 34
d Ls O O
5 0, 1.2.3,4 3,
5,3 0,1,2,4 dlo= mir ( o, hto) o0
dj 4 , 14
dla) w
d[4)39
5.3,1 D,2, 4 dle)- 2, 39
dLo) 29
du) 3
5,3,1,3 o, dlo) 49 3
dlA) 34
S3,1.24 d o)= 49
5,3,1,2,0