Assignment 4
Assignment 4
i=1,j=1
While i<=n,j<=m
If si = sj’,
kj=i,
I = i+1
j = j+1
else
i=i+1
If j = m+1
3.(a)
No it is false.
Le the vertices of graph G be {v1,v2,..v4} and let the weight from edge vi to vj be i+j.
So every tree has to pass through vertices v1 and v4 and hence has a minimum bottleneck weight of 5.
One such tree is v3,v2, v1,v4.
v2 v3
v1
4.
Matching(n)
If n is a leaf
return 0
is_match = False
if not matching(x):
if is_matched:
return 0
else
is_matched= True
if is_matched:
else:
5. Just like in binary Huffman coding, here we pick the three smallest frequencies, join them together
and create a node with the frequency equal to the sum of three, and continue.
As everytime the three nodes are combined and give rise to one node, so we have to make sure that to
end up with one node, we have to start with an odd number of nodes. If not, we can add a dummy node
with zero frequency.
Suppose G=(V,T) is an optimal tree and v is an internal vertex at the maximum distance from the root.
Suppose also that a(i), one of the children of v, is not one of the two letters of minimal weight. Then
exchange a(i) with a minimal weight letter. This leads to the tree build by the algorithm and does not
increase the cost function
Ref : http://people.math.gatech.edu/~randall/Algs05/HW8_solns.pdf