You are on page 1of 19

J21 ASSIGNTENT-2

eplain enuial pracede | mathod oo


Teedy Method

ready metho d The greedy mathod


ona o the Strateqies Ke Ditdt and Conqua
e d to 4olve the prololems
Thu meth od used o soleng
Opumazati on pvoblems. m optimizallbn
problem y a Problem that dimands eithe
matimum (8) mini mum results
The Greedy mathod d the mplast ond
9traighiforwand approadh. t not an

aladuthm, buct it i a techniaue

reed aqovithms build a oluion


pat by pat hoo inq the nett paos in
uch a way that f gives an immedial

benait
This
Tha approach never TeconideTS the
the
choi u taken preiowly.
Th approah mamad nly ued to olwe
opti mzation problem
On many oblems,, doe Tot produa
an optimol ouutibn houg tqiv an
ape Youmoti outuon in a eas dnable n
choice propertyJt maky tocály
qreedy
optimalhetcn
optimat
in hope thad hu dhu 0ad
1 qobally optimal olution Soiutwn
substrudure : optimal
optimal

Conains optimal ub Neluon


Compornenu of.reedy gorithm
thot u
6et: A Solution
Candi'date d
Known a
e m the set
u
Cveaded
Candidote st
Th tundion
Selection fun ion
or subset
nd wed i choose the Candidate
which can be added im the eution
Feaybiuty unduon A undion that
to daten mi ne whut her the Candidate
wsed
be used to Centu bule to
(&t) Subset can

th ouuion d mot
wd
wed
cbi etine undion A untiom 1

to aman
agn the valun to the olution di the'

patal oution
Ve
Solution This tunttion
hundtion
ed io intima whit he the Coriplute
uce undtion ha been reathed o not.

AppLicatt an of eeedy Hethod


Job Seauenung with deadlt neg
a) Hinimum cost spanning iiee
3) koap sack poblerm

4) Single Source Sho test path

Sequenung with Deadun


O Job a ngit
seuenung
otjobs on Callea
The
The Ctrainu
u
daadiima
with
proceysot Deadlini
seuenung.with
a Tob
coide7 st o jobs duadliia aard
duadiirt
hasá dayined
Eath job with it
assouated

Phett
ordg uhemn
m

o a job i iven
Th proit diodlinn
ternpluted
within i
tha
do is avaiablu joi
Onla om Proceysdv

PYoces'na au, th jobs


Prouo tatu
unit oh tüme to
Cempite a job
adopted to datermi
Algduihnm
reed om
to
s e a i t e d bot
how the mextjob
how
optimal

Step 01 Sovt all


the ivem jobs n
decreaing order t h e i r Proit

Step -02
chack the Value maXimum dead iins

DTaw a natt chart whee mantimum


time on Gnatt h a t he valu
maimum deadtine
step-03 Pick up th obs one by one
Pu the job on gnat haot o j0n a

poible om O enuing tha the job


ob

qet Complet ed bejsu. dtu daod lin


Exampl&

Jobs J J 33 J T6 6

Dead 5 2 2

100
Prot 00 180 190 30o 120

soluion
Stepo1 Sort all the qiven jobs in decreasirg

Ovde ther PYoit

Jobs JY J J3 J2 T5 J6

Dead 6 3 2

Prolts 300 200 20 18o 10100

Step oa volu d) maimum dradune = 5

So drauw natt dhat with max t i t dnn


antt cha 5 untty

3 5

ontt chat
Step 3
3 5
we t a k Tob JU

nu dt doadlime u

Step
J
5
We taRL TOb J
ne daadine U5

Step 5
T 3 J
O 2 :3 A- 5
we tak Job J3
ina ii dead ine i 3

Step 6
TJ4J3
3 4
,
we take 3ob Jy
nu, its diadline 3, So we plau
it in
rst empty cl behdi daadline 3
becaw Se cand and third Celus a

alsaady led

Step 7 J4 3 J5
2 3 5
Re Tob J5
we La
y 4A
dradime
nuls,
J6 who
the onlyob p
Now
d i a d u ne J
alhtady Ocuped., betöu
Al lou an

dleadline
Can not be Completed.
Job J6
Th
l a i mum
eane P of
Pro\it o Jy vo
voit d3
Proit ot J t
Pro J

180 + 300. t 10 1a0 t 200

10 units

Minumum CoSt Spanning Tree


tzee a bset o
Spannin9 Tree: A5panne nq
ha) a the v e t u c
that
undire ted qraph
ar
an
Conneted by umurm no of edaes
in à
3f all the VedticeS a Connect ed

thwe etisty a eazt &ne


9raph, then

Spanneng tree' n a
raph there yexASt
moe than one Spannin tree

ma 3raph, these máy eist muou than


ona pan ning ree.
Propenies
A Spannim tee does hot have do yd
Any voter can be reahed hum any
ethw Ventex

Minimum Spannina Tvee


inimum Spaoning Tree i a Sparning
hed whech hay. minimum totat Ldt

A Mimum panning Tree (MST) 4 a Subset


o edges da omneded wugnted undivectd
raph th at Comne t aL v o t i t e t h u
with minimum possible totàl edge' wught
MST makas
use o prisms aladithm
e KYuskal algou thm-
f thw au Mnumben d veicu) tha
panno9 e should have n no-o edats
* Each edp cth qraph a3 asociated
with a weiqh and the eistt moi t h a
b anning ee we need to n d thi

minimum spannia e o
ne. qraph
MoveoveN, f the eist: any.duplucU
werg hted edgethe.aph ma haue
rnuipie minimum spanning.Ue
( au uwo methoda do n d tinimum

Spann n9 Tree

KyukalU Alqouthm
Primb Algou thm

Kruska Algduthm
Kruskal Algduthm a tamo 3ree
algithm
uinimum
t sed bdi nding h
ed
Spanning ToeeM6T) o} a giun qragh
To appl Krukal Algduthm, thi qi vem
muust be weiqhted connedted ard
qraph
undlueded

Sovt all edqei in meeang dld


Step1
o thu edge weiqghts
Step 2 Pick the Smallest edqe

step3 : Check if the new edge create


Cy cle l ) Loop in a spanning tree

step f it doesnt from the cycle


includde that edge. in 1ST
then

othenwi s e du Cand t

t
Step 5 Repeot uom step 2 canti
incudu l-I edges in MST.

entioned above, ou
wng
w ng th steps
will quwidl a unumum spannu n tre

StrutuTe
6

Soufce Verter Deatinatuo) wetgh


Veter

E F 2

D 2

F
D

5
D

OPiek edqe E -F no Cyd i

bysuyudincdud it
ficK edge D no cy
ouvud indude t

Pck
Pick edqe 6-

o cls , oumud
and C F

Pi edae c-0 djdt u bmud


diucod it

Should be
Pick edge B-F.
di S caid ed

Pick edge B-D y bdurnad


d iscand d

Pick edqe A-B in cudL it

3
edge A-G carded
be cauuy eyde will be tsmad

no of dgi aualh to (v-1)


th aladithm stops h
V=

(v-1) (6-1)
= 5 ed

OCE Loq V)

Paims Alqirthm it sed to


ind
the mentmum 6panning trec Hom a p h
Uses qreaduy aPPYach
t stavd wrth an, empty Spannung

>Iniialize the olgbuthm by choosurg


vesiex

Find the minimum ueuh edqe


Cm neted to Sowie naie and anothøv
nod and add i t to the tre
Kap epeadu h s procey unds,s w
ind the minYmum 6panning tBe0

29
0-

12

Step o1
10

step 0a

25 -
Step 03

6)

Step o1
90

2
Stepo5 o

2
25
.22

Step O6
10

12

2n
bee inuded
Since all veticy ave
in 1ST we stopP
NOW, únimum COst Spanrua Tsee
Sum all eodat
10 425 + 22 t12 + 16 t

11 unl
Fradiomal Knapsauk
fractional napsa tk pYoblem

aLo oe o the techntque which a u used

to
to o th knapSackpvoblem

In 4a Ctuoa Kropsack th tenms


bYokam nordAn to
ae
The Problem
in whick we breok
P oit
tem nown a haional ¥nopsat

pYoblemm
e ets 2

Poyit S

wetaht 3 5 3 2

Plw 5 3-3 5 3

W=5 n

Pott wught Aamaimung


objet w) lght
,15-1 IY
5 14-1 3
O 3 13-3 1O

5 10-5 5
3
5-3

a-a O

51

monuMum pohut
ue c a l c u l a t the
n oppYoah,
e
and accoicungy,
atio ot, Phofit wqht
item wth
scluut
tha item. The
we will
would be selacted host
host.
th hghut
Tati
o
çalculated
we
mthe aboue eiam p
t h Yatio Prott.wetqht

'W weight othe Knapsack


5

= n0 temy

objet .5 5:

objet2 tol3 333

object 3:515 3
Objett 4H
objeut 5 1 =

objett 6 913 = 33

object : 2 =2

hL objeda with iqhuyt Plu Totto


c t ed bTst
TOta PYofd =
3 5 5 + 10 +1544 4
51
the Souue hdtet Path
Stnga
ue aou qiven a uetqhted
Suppose
ith 9Taph and we
osKed to ind a

st sUme vedei y to each


Shortet podth hom
om
thi uweghy
ted othu vete. in G. Viewin9
dustancu
Thi problem i
a
th edqA
poth
caliled a i n g - Sounce. hoteyt
be a

The shotet path problem con


be
utethot
Consecutuie vetu
Path
appYoPYiat dved ed edqe.
Conneted b. an

Tha
Jat (v, E) raph
be a
.

to nd thehötet path thom


Problm
Sowice Vete v to Temainu ng a
a given
tA Ventice ithe en 9raph t

all the distance


oumed that
th
POitiu The stating. Vente the
and the lagti
colled ouce v e t e .

veex, o pat Callad dustuinaton veeter

the obedteve ot ngle o u c e


main

o t est path problem i whave to knd

om onu Vatex to
3hot et ist an
7emanunq all Vestu C8 in qien qraph
The alqorithm a the Sing SowC
hdtet path wing reedy mthads a d
tD a mpl alokúthm Called

Dijkstra's Algorithm
Stngla youce hdtet Patk
Relaaton
f dCuj+ cCuv)< dfv])

dv d [uj t c(u, v)

2 D

b
2

ete Tminimum Rote


ost
A B A E6

A6 6 C|
A D 5 A E D
AE A E
oijkstra Algorithm
amou
Djkata 1duthm a veru

ud algouthm. t u used hel uen


owna shdtest path
ngta
D K sta aigduthm w only th
Comneted graph
Tt wos qraphs that
KA only tl thoe

do not Cortain any negatiut weraht edas

Dijkstra olgorithim
woYks hol dire ted
o weu as undi'rect ed p h
make o th at thne
Step i
nagatie edge welghu
distance
td Source vetex
Set
Step dLstacu
and Set a l l other
a zero
sourca
wthout having diret Edge hom
td that wrent Vetex) to
vete
Intuty
Sep 3 Rulai all vetico adjanCat
td the Cwnet Veter

th dsest Vete a^ the


Step 4 Choo
nut cwvarterter

Step 5 RePeat steps 3 and y until

weeach duunatu on
12
LO

dfuj= A d CV F

&Cuj4c (u,v) d[VJ


[ ] d[uj t c(u, v)

D E

A 2

C
1 19
D
L6 H
F

You might also like