This preview shows pages 1–3. Sign up to view the full content.
Computer Science C73
November 7, 2007
Scarborough Campus
University of Toronto
Solutions for Homework Assignment #3
Answer to Question 1.
a.
The array of edit distances of all preFxes of the two strings computed by the algorithm is shown below.
L
O
O
P
Y
0
1
2
3
4
5
0
0
1
2
3
4
5
S
1
1
1
2
3
4
5
N
2
2
2
2
3
4
5
O
3
3
3
2
2
3
4
O
4
4
4
3
2
3
4
P
5
5
5
4
3
2
3
b.
The DAG of subproblems being solved with the edges appropriately labeled is shown below. A shortest
(unique, in this case) path from the smallest subproblem to the largest one is identiFed with heavy edges.
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
0
1
1
1
1
1
1
1
O
S
N
O
O
P
L
O
P
Y
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
c.
Any path through the DAG shown above consists of edges each of which goes down, to the right, or
diagonally. An edge going down corresponds to deleting a letter of the Frst string; an edge going to the
right corresponds to inserting a letter; and an edge labeled 1 going diagonally corresponds to changing
a letter. (A diagonal edge labeled 0 corresponds to a match, and results in no editing operation.) More
precisely, an edge from (
i
−
1
,j
) to (
i,j
) corresponds to deleting the
j
th letter of the Frst string. An edge
1
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document from (
i,j
−
1) to (
i,j
) corresponds to inserting the
j
th letter of the second string. An edge labeled 1 from
(
i
−
1
,j
−
1) to (
i,j
) corresponds to changing the
i
th letter of the Frst string to the
j
the letter of the
second string.
Answer to Question 2.
The inputs are positive integers
w
1
,w
2
,... ,w
n
,W,
Δ.
Let
S
⊆ {
1
,... ,n
}
. We deFne the
value
of
S
to be
∑
i
∈
S
w
i
. We say that a set
S
⊆ {
1
,... ,n
}
is
w

legal
if its value is at most
w
, and for all
i,j
∈
S
such that
i
n
=
j
,

w
i
−
w
j
 ≥
Δ. ±or 0
≤
i
≤
n
and 0
≤
w
≤
W
,
let
S
(
i,w
) be a
w
legal subset of
{
1
,... ,i
}
of maximum value. The set we are seeking is
S
(
n,W
). Let
M
(
i,w
) be the value of
S
(
i,w
).
We now give (and justify) a recursive formula to compute
M
(
i,w
). To do so, it is convenient to Frst
sort the Frst
n
inputs so that
w
1
≤
w
2
≤
...
≤
w
n
, and to deFne, for each 1
≤
i
≤
n
,
p
(
i
) = max
{
j
:
j <
i
and
w
i
−
w
j
≥
Δ
}
, where we take max
∅
= 0. (That is,
p
(
i
) is the largest index preceding
i
of an input
that is “su²ciently far apart” from
w
i
.) Note that if
i
is in a
w
legal set
S
,
p
(
i
) is the largest index smaller
than
i
that can be in
S
. Let 0
≤
i
≤
n
and 0
≤
w
≤
W
.
Case 1.
i
= 0. Then clearly
M
(0
,w
) = 0.
Case 2.
i
≥
1 and
w
i
> w
. In this case,
i /
∈
S
(
i,w
) (since
w
i
by itself is not
w
legal). Therefore,
S
(
i,w
) =
S
(
i
−
1
,w
), and so
M
(
i,w
) =
M
(
i
−
1
,w
).
Case 3.
This is the end of the preview. Sign up
to
access the rest of the document.
This note was uploaded on 02/10/2009 for the course RLG 100 taught by Professor Pearly during the Spring '08 term at University of Toronto Toronto.
 Spring '08
 Pearly

Click to edit the document details