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

DAA Assignment 4

Uploaded by

Doze uncle
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

DAA Assignment 4

Uploaded by

Doze uncle
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Assignment -4

217 Nor ,
in addition to considering the revenue generated for each piece of rod ,

must also consider the cost of every cut


" "
we C .

The the of the prices of the pieces the


• . new revenue is now sum minus


costs of making the cult .

We can
modify the BOTTOM -
UP -
CUT -

ROD algorithm as follows .

MODIFIED -

CUT -

ROD C p ,
n, c) :

let r -10 n ] be a new


array
. . .

v10 ] =
0

for 8=1 to n :

q
=
p[j ] 5

for E- 1 to
j
-

1 :

g =
Max ( q p [ i],
+ r[ j -
i] -

c) 7

t[j ] q =

return KEN

We need to subtract the cost c from the revenue in line 7 , for every
iteration except for when i==j aka no cult .

q =p Ej ] ,
as this the rod having zero cult for a
given length j .

It is then compared against all the other possible combinations of cuts to see if it
iteration
is the one
yielding the highest revenue or not for the given .
227 OPTIMAL -

BST -

MULTIPLE (p , g, n ) :

let e[ I . . .
n -11 ,
0 . . . n ] ,
w [I . . - n -11,0 . . . n
] ,
and
root [ I . . .
n
,
I . . . n ] be new tables .

for it to n -11 :

e[i i i ] ,
- =
Gi -
i

w[ i i i ] ,
-
=

qi -1
for 1--1 to n :
for it to n
-
l -11 :

j it l
=
l
-

e [ i. j ]
= as

w[ i. j ] =
w[ i j i ] ,
-

+
pj + qj
for r=
iloj :

f- =
] + eft -11
ii. r -
i
,
j] + w[i. j )
if t==e[ i.j ] :
return true
it t < e[ i. j ] :
eli ,j]=t
root [ i. j ] -
-
t

return false
Let T be a MST Let TO
237 containing an
edge d.v7 .
& -11 be
the two trees obtained after edge (v.v) from the MSTT
removing .

Let V0 & V1 be the vertices of To & IT respectively .

Consider a cut which separates V0 & V1 .

Assure these edge whose less than d. v7 ñ this


exists an
weight is
cut .
Then , if
take this edge we can construct a minimum spanning
we ,

tree 7 of the whole graph by just adding He edge to to To , .

This new MST T


'
has weight less than that of T .
However that ,

is not possible as T is a MST .


Therefore ,
our assumption that these
exists an
edge whose weight is less than ( vid is incorrect .

By proof by contradiction if these is an edge did in MST


• .
,
a
,

then it is a light edge crossing some cut of the graph .


247 At each step of the algorithm we will add an edge from a vertex in the
tree created so far to a vertex not in the tree such that this edge has minimum ,

weight Thus it will be useful to know for each vertex not in the tree
.
, , ,

the edge from that vertex to some vertex in the tree of minimal weight .

We will store this information in an array A where Ali Hw ) if w is the ,


=

weight of d. v7 and is minimal the weights of edges from u to some


among
vertex r in the tree built so far .
We will use A [v7 . 1 to access v and
AE u ] .
2 to access W .

PRIM -
A 29 CG ,
w, t ) :

initialize A with
every entry =
(Mt ,
as )
T= { v3
for it to V :

if Adj Er ,
i] ! =
0

A [ i] = (r ,
wcr, i ) )

for each u in V -
T :

K =
( A [i ] 2)
min .

F- TV { K }
K.TT =
AEK ] .
1

for 0--1 to V :

i] ! and ER i ]
if Adj [K ,
=
0
Adj ,
< Ali ] . 2

A [i] =
(k Adj [ k i] )
, ,
257 a ? In Bexvvka's algorithm
disjoint
the worst case scenario in every iteration is
, getting
the maximum number of Subgraphs For example casider a F- 16 graph
. .
,
.

In the 1st iteration of Borurkai algorithm ,


we can observe that the maximum
number of subgraphs would be 8 .

V1 V3 V5 V7 V9 V11 V13 V15

V2 V4 V6 V8 V10 V12 V14 V16

Taking the worst-case scenario in iteration 2


,
the number of subgraphs would
reduce to 4 .

V1 V3 V5 V7 V9 V11 V13 V15

V2 V4 V6 V8 V10 V12 V14 V16

Trituration 3, the roof subgraphs reduces -62 .

V1 V3 V5 V7 V9 V11 V13 V15

V2 V4 V6 V8 V10 V12 V14 V16

In iteration 4. theme of subgraphs reduces to 1- & the MST is cheated .

V1 V3 V5 V7 V9 V11 V13 V15

V2 V4 V6 V8 V10 V12 V14 V16

P.TO
In the number of subgraphs reduces by

• .

every iteration ,
2 .

So for of iterations to
vertices
say that
, an n -

graph ,
we can the no
create MST
using Boruvkas algorithm would be
logan
'
a .

For

:
iterations to
a 11=16 graph ,
we would require at most logit 4
create the MST
using Boruvkai algorithm .

10 22 15
b) v, v2 v3 v4
15
29 28 32
28
20 32 2s
v5 V6 vq vg
90 69 72
3° 42 35
v10 v1 , V12
vq
97
52
40 52 45
y, } v14 us v16

After 1st iteration ,

10 15
v1 v2 V3 V4

2° ZS
V5 V6 v7 v8

3° 35
V10 V11 V12
V9

4° 45
viz v14 Vis V16

P.TO 0
After 2nd iteration ,

10 22 15
v1 v2 v3 v4

20 32 25
v5 v6 up vg

3° 42 35
v10 v11 V12
vq

40 52 45
viz v14 us v16

After 3rd iteration ,

10 22 15
v1 v2 v3 v4
32
20 32 2s
v5 V6 up vg

3° 42 35
v10 v1 , V12
vq
52
40 52 45
µg v14 us v16

After 4th iteration,

10 22 15
v1 v2 v3 v4
32
20 32 2s
v5 V6 up vg

72
3° 42 35
v10 v1 , V12
vq
52
40 52 45
µg v14 us v16

You might also like