DAA Assignment 4
DAA Assignment 4
217 Nor ,
in addition to considering the revenue generated for each piece of rod ,
We can
modify the BOTTOM -
UP -
CUT -
MODIFIED -
CUT -
ROD C p ,
n, c) :
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 .
• .
,
a
,
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 .
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
. .
,
.
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
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
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
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