This preview shows pages 1–3. Sign up to view the full content.
Homework problems for CMSC423
1 Longest monotonically increasing subsequence
Let’s ﬁnd the length of MIS ﬁrst. Suppose we know the length of a sequence
ending at (
i

1)
th
index — L[i1]. If next number
C
i
is greater than
C
i

1
, then
we can extend (
i

1)
th
sequence with
C
i
:
Length(
i
) = Length(
C
i

1
) + 1
.
However, the sequence ending at
i

1 is not necessarily the longest sequence we
have seen so far: there may have been a subsequence ending somewhere before
i

1 that was longer:
5
6
1
7
2
8
.. .
i

1
i
In example above, sequence ending with 2 is of length 2 and we can extend it
with 8 (2
<
8), but a sequence [5, 6, 7] is longer and it too can be extended
with 8.
To ﬁnd the longest increasing subsequence that ﬁts somewhere between 0
and
i
, we would need to consider all subsequences ending somewhere before
i
,
and see if we can extend any of them:
Algorithm 1
Finding locally long subsequence between 0 and
i
for
j
= 0
→
i

1
do
if
C
j
< C
i
AND Length(
j
) + 1
>
Length(
i
)
then
Length(
i
)
←
Length(
j
) + 1
end if
end for
To compute the longest increasing subsequence within the whole string
S
,
we need to start from the left and keep extending locally longest subsequences:
Algorithm 2
Finding globally long subsequence in
S
for
i
= 0
→
N

1
do
for
j
= 0
→
i

1
do
if
C
j
< C
i
AND Length(
j
) + 1
>
Length(
i
)
then
Length(
i
)
←
Length(
j
) + 1
end if
end for
end for
1
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentWe can also write down the problem as a recurrence:
Length
(
i
) = max
j<i
n
Length
(
j
) + 1 s.t.
C
j
< C
i
Here, we go through all
j
less that
i
; for
j
such that
C
j
< C
i
, we consider a
Length(
j
) of the longest subsequence ending at or before that index and pick a
maximum among those.
2 Guaranteed gap limit
When
k
= 0, we are guaranteed that there will be no gaps in the alignment. The
only two options left are mismatches and matches. Geometrically, that means
we do not ever stray from the diagonal path from the lower left cell to the upper
right in the global alignment matrix.
Now, suppose we may have up to 1 gap. That implies that the optimal
This is the end of the preview. Sign up
to
access the rest of the document.
 Fall '07
 staff

Click to edit the document details