Rubric (for all dynamic programming problems):
•
6 points for a correct recurrence, described either using mathematical notation
or as pseudocode for a recursive algorithm.

1
for each missing or incorrect
base case.

2
for a
minor
mistake (like a typo or an offbyone error) in a
recursive case.

1
for not describing what the function represents. No credit for
the rest of the problem if the recurrence is incorrect.
•
1 point for describing the memoization data structure.
•
2 points for describing a correct evaluation order. A clear picture is sufficient for
full credit.
•
1 point for analyzing the running time.
Official solutions will always include pseudocode for the final dynamic program
ming algorithm, but this is
not
required for full credit. On the other hand, if correct
pseudocode for the dynamic programming algorithm
is
included, it is not necessary to
separately describe the recurrence, the memoization data structure, or the evaluation
order.
The official solution will provide a target time bound. Algorithms faster than the
official solution are worth more points (as extra credit); algorithms slower than the
official solution are worth fewer points. For slower algorithms, partial credit is scaled to
the lower maximum score. For example, if the full algorithm would be worth 5 points,
just the recurrence is worth 3 points.
It is
not
necessary to state a space bound. There is no penalty for using more space
than the official solution, but
+
1
extra credit for using less space with the same (or
better) running time.
Any correct algorithm, no matter how slow, is worth at least 2
½
points
,
assuming it is properly analyzed.
1
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
CS 473
Homework 2 Solutions (February 10, 2010)
Spring 2010
1.
A
palindrome
is a string that reads the same forwards and backwards, like x, pop, noon, redivider, or
"sator arepo tenet opera rotas". Describe and analyze an algorithm to find the length of the longest
subsequence of a given string that is also a palindrome.
Solution:
Suppose the input sequence is
A
[
1
...
n
]
. For any indices
i
and
j
, let
LLPS
(
i
,
j
)
denote
the length of the longest palindromic subsequence of the substring
A
[
i
...
j
]
. This function can be
defined recursively as follows:
LLPS
(
i
,
j
) =
0
if
i
>
j
1
if
i
=
j
LLPS
(
i
+
1,
j

1
) +
2
if
i
<
j
and
A
[
i
] =
A
[
j
]
max
{
LLPS
(
i
+
1,
j
)
,
LLPS
(
i
,
j

1
)
}
otherwise
The base cases are trivial—the empty string is the concatenation of zero palindromes, and any
onecharacter string is itself a palindrome. In the general case, if
A
[
i
]
and
A
[
j
]
, then they both
belong to the longest palindrome subsequence of
A
[
i
..
j
]
. (Let
B
be any palindrome subsequence
of
A
[
i
..
j
]
; replacing the first and last characters of
B
with
A
[
i
]
and
A
[
j
]
gives another palindrome
subsequence of the same length.) Otherwise, either
A
[
i
]
or
A
[
j
]
(or possibly both) does not belong
to the longest palindrome subsequence of
A
[
i
..
j
]
, but we don’t know which.
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '08
 Chekuri,C
 Dynamic Programming, C Programming, False False False, Boolean formula, false boolean formula, OTH FALSE

Click to edit the document details