



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Project; Class: Data Structures and Algorithms; Subject: Computer Science; University: University of New Mexico; Term: Fall 2005;
Typology: Study Guides, Projects, Research
1 / 7
This page cannot be seen from the preview
Don't miss anything!




Jared Saia
University of New Mexico
Administrative
Dynamic Programming
Course Evaluations
The project is due this Thursday in class.
credit but a complete project turned in late will get no credit)partially completed project turned in on time will get someThis deadline is strict - late projects will recieve no credit. (A
Each Group should turn in one project consisting of:
About 6-12 pages of text and figures
possible)6-12 figures (please put multiple figures on one page where
members if appropriate.Task list giving which tasks were performed by which group
This should be signed by all mem-
bers of the group.
Each
individual
should turn in the following:
An
evaluation
of the contribution to the group project of
cellent).every member of your group on a scale of 1(poor) to 10(ex-
To do this, write down the name of each member
of your group (including yourself),
and put a number be-
tween 1 and 10 next to each name.
Please be honest and
professional in your evaluation.
Your evaluation will be one
of your group.factor used to determine the project grade for each member
Before you turn in the project:
Reread “The Top
n
Project Mistakes” section in the project
description section on the course web page
You will loose points if you make these same mistakes
the following way: Dynamic Programming is different than Divide and Conquer in
bines solutions to solve original problemproblems, solves the subproblems recursively and then com-“Divide and Conquer” divides problem into independent sub-
independent, i.e. the subproblems share subsubproblemsDynamic Programming is used when the subproblems are not
work than necessaryFor these kinds of problems, divide and conquer does more
saves the answer in a table for future referenceDynamic Programming solves each subproblem once only and
Formulate the problem recursively.
. Write down a formula
smaller subproblemsfor the whole problem as a simple combination of answers to
sidering the intermediate subproblems in the correct order.recurrence and works its way up to the final solution by con- Write an algorithm that starts with the base cases of yourBuild solutions to your recurrence from the bottom up.
problems. This is frequentlyNote: Dynamic Programs store the results of intermediate sub-
but not always
done with some type
of table.
remaining alignment must also be optimalIf we remove the last column in an optimal alignment, the
subalignment of all but the last column.Easy to prove by contradiction: Assume there is some better
Then we can just
a better overall alignment.paste the last column onto this better subalignment to get
Note:
The last column can be either:
aligned with a character on bottomaligned with a blank on bottom or 3) a character on topaligned with a character on bottom, 2) a character on top
find a recursive definitionTo develop a DP algorithm for this problem, we first need to
Assume we have a
m
length string
and an
n
length string
Let
i, j
) be the edit distance between the first
i characters
of
and the first
j
characters of
Then what we want to find is
n, m
Say we want to compute
i, j
) for some
i
and
j
tion toFurther say that the “Recursion Fairy” can tell us the solu-
i ′ , j
), for all′
i ′ ≤
i ,
j ′ ≤
j ,
except
for
i ′ =
i
and
j ′ =
j
Q: Can we compute
i, j
) efficiently with help from the our
fairy friend?
There are three possible cases:
Insertion:
i, j
i (^) −
, j
)
Deletion:
i, j
i, j
Substitution:
If
a i =
b j , E
( i, j
i −
1 , j
−
1), else
i, j
i (^) −
, j
Let
i ] 6 =
j ]) = 1 if
i ] and
j ] are different, and 0 if they
are the same. Then:
i, j
) = min
i (^) −
, j
) + 1
i, j
i (^) −
, j
i ] 6 =
j ])
It’s not too hard to see that:
E
(
, j
) =
j
for all
j , since the
j
characters of
must be
aligned with blanks
Similarly,
i, (^) 0) =
i
for all
i
gorithmWe now have enough info to directly create a recursive al-
the following recurrence:The run time of this recursive algorithm would be given by
m,
, n
m, n
m, n
m
(^) −
(^1)
, n
n
−
(^1)
, m
Solution:
n, n
n ), which is terribly, terribly
slow.
We can build up a
m
n
table which contains all values of
i, j
in the 0-th row and 0-th columnWe start by filling in the base cases for this table: the entries
above, to the left and above and to the left.To fill in any other entry, we need to know the values directly
Thus we can fill in the table in the standard way:
left to
in each cell are always availableright and top down to ensure that the entries we need to fill
optimal alignmentIn this code, we do not keep info around to reconstruct the
to achieve the current cell’s minimum edit distancewhich stores, for each cell, a pointer to the cell that was usedHowever, it is a simple matter to keep around another array
pointers from the bottom rightTo reconstruct a solution, we then need only follow these
corner up
to the top left
corner
and “bab”.Create a string alignment table for the two strings “abba”
Put “abba” at the top of the table and “bab”
on the left side
Qi: (
i = 1
(^) 5) What is the
i -th row of your table
ments achieve it?Q6: What is the minimum edit distance and how many align-
the recurrence from the bottom up1) formulated the problem recursively 2) built a solution toTo solve the string alignment problem, we did the following:
We’ve seen a use of DP for the String Alignment Problem
tiplyMany other uses including: Finding the optimal way to mul-
matrices,
algorithms
for
scheduling
jobs,
finding
the
gorithm), etc.shortest paths in a graph, application in AI (the Viterbi al-
lem and then use memorization (i.e. we build a table)In all cases, we first find a recursive formulation of the prob-