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

Assignment 4

Uploaded by

huapei30
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Assignment 4

Uploaded by

huapei30
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1. Let S = {s1,s2..

sn} -> Length n


S’ = {s1’,s2’..sm’} -> Length m

Let k1,k2..kn denote the matches


I -> the current position in S
j -> current position in S’

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

return Subsequence : {k1,k2,..km}

Else S’ is not a subsequence

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.

But below is the minimum spanning tree

v2 v3
v1

Hence every minimum bottleneck


tree is not a minimum spanning tree v4

(b). This is true


This is because by definition, a minimum spanning tree is comprised of the least weighted edges

4.
Matching(n)

If n is a leaf

return 0

is_match = False

for each child x of n:

if not matching(x):

if is_matched:

return 0

else

is_matched= True

if is_matched:

return ‘it is a perfect match’

else:

return ‘it is not a perfect match’

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.

Thus the modified algorithm looks as follows:

create a list H of leaves i.e the alphabet symbols

while H contains at least 3 elements

if H contains even number of elements,

Add element z with w(z)=0

Pick elements x,y,z of minimum weight

remove elements x,y,z from H

create new element v, assign weight w(v) = w(x)+w(y)+w(z) and include it in H


Proof: Here also we can use the exchange argument just like binary Huffman code.

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

You might also like