0% found this document useful (0 votes)
18 views5 pages

HW 1

The document outlines Homework 1 due on January 24, 2021, which includes dynamic programming problems from Chapter 6 of a textbook. It presents various problems such as finding the maximum sum of contiguous subsequences, longest common substrings, and optimal binary search trees, along with specific instructions for each problem. Additionally, it includes detailed tasks for two specific problems, requiring algorithm design and analysis.

Uploaded by

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

HW 1

The document outlines Homework 1 due on January 24, 2021, which includes dynamic programming problems from Chapter 6 of a textbook. It presents various problems such as finding the maximum sum of contiguous subsequences, longest common substrings, and optimal binary search trees, along with specific instructions for each problem. Additionally, it includes detailed tasks for two specific problems, requiring algorithm design and analysis.

Uploaded by

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

Name: 1

Homework 1.
Due: Monday, January, 24 2021 before 8:00am via Gradescope.
[DPV] Practice Dynamic Programming Problems
Suggested reading: Chapter 6 of the book.

[DPV] Problem 6.1 – Maximum sum


A contiguous subsequence of a list S is a subsequence made up of consecutive elements of S...
[DPV] Problem 6.4 – Dictionary lookup
You are given a string of n characters s[1...n],which you believe to be a corrupted text document
in which all punctuation has vanished...
[DPV] Problem 6.8 – Longest common substring
Given two strings x = x1 x2 . . . xn and y = y1 y2 . . . ym we wish to find the length of their longest
common substrings...
[DPV] Problem 6.17 – Making-change I
Given an unlimited supply of coins of denominations x1, x2, . . . , xn, we which to make change
for a value v...
[DPV] Problem 6.18 – Making change II
Consider the following variation on the change-making problem (Exercise 6.17): you are given
denominations x1, x2, . . . , xn, ...
[DPV] Problem 6.20 – Optimal Binary Search Tree
Suppose we know the frequency with which keywords occur in programs of a certain language,
for instance ...
[DPV] Problem 6.26 – Alignment
Sequence alignment. When a new gene is discovered, a standard approach to understanding its
function is to look through a database of known genes and find close matches...

See next page for homework problems.

1
Name: 2

Problem 1 Longest Common Sub*!?*


Given two strings X = x1 , x2 , . . . , xn and Y = y1 , y2 , . . . , ym give a dynamic programming
algorithm to find the length k of the longest string Z = z1 , . . . , zk where Z appears as a substring
of X and as a subsequence of Y . Recall, a substring is consecutive elements.
For example, for the following input:

X = a, b, d, b, a, b, f, g, d
Y = b, e, t, f, d, b, f, a, f, r

then the answer is 4 (since, b, d, b, a is a substring of X and it is also a subsequence of Y). You do
not need to output the actual substring, just its length.
(Faster (and correct) in asymptotic O(·) notation is worth more credit.)
(a) Define the entries of your table in words. E.g., T (i) or T (i, j) is ....

(b) State recurrence for entries of table in terms of smaller subproblems.

2
Name: 3

(c) Write pseudocode for your algorithm to solve this problem.

(d) Analyze the running time of your algorithm.

3
Name: 4

Problem 2 (The collector)


You are given a n × n matrix M of integers. Suppose you walk along the matrix starting at coor-
dinate (1, 1) (top left corner) in order to reach coordinate (n, n) (lower right corner) accumulating
the integers along the way. At any coordinate, you may only move right, down or diagonally right-
down. That is, if you are at coordinate (i, j), you can only move to either (i + 1, j) or (i, j + 1) or
(i + 1, j + 1) in a single step. Design a dynamic programming algorithm to find the maximum sum
you can accumulate in your walk subject to the above constraints.

Example
Input:  
3 30 12
M = −12 7 −9
39 −2 15
Output: 55
Explanation: This sum comes from the path (1, 1) → (1, 2) → (2, 2) → (3, 3). The accumulated sum
is M [1][1] + M [1][2] + M [2][2] + M [3][3] = 3 + 30 + 7 + 15 = 55.

(a) Define the entries of your table in words. E.g., T (i) or T (i, j) is ....

(b) State recurrence for entries of table in terms of smaller subproblems.

4
Name: 5

(c) Write pseudocode for your algorithm to solve this problem.

(d) Analyze the running time of your algorithm.

You might also like