Dynamic Programming - 2
Dynamic Programming - 2
Sharath Raghvendra
Associate Professor, Dept. of Computer Science,
Virginia Tech
Fall 2022
Agenda
▪ Today’s topic
▪ Dynamic Programming (Continued)
▪ RNA Secondary Structure Determination
▪ Edit Distance
▪ Shortest path with negative edge costs
▪ After that…
▪ NP-Completeness and reductions between problems (Chapter 8)
Principles of Dynamic Programming
▪ Applications:
▪ spell checkers,
▪ natural language translation,
▪ bioinformatics.
Application
How does google know that “dynamic” and
Dymanic are similar?
Edit Distance
▪ Given initial string x and final string y, what is the minimum number of edits
required to convert string x to string y.
▪ Valid edits include:
▪ Insert a character to x
▪ Delete a character from x
▪ Change a character in x to another character
Example
Alternately, we can ask how well the words line-up? Such line-ups are called alignments.
Example
Alternately, we can ask how well the words line-up? Such line-ups are called alignments.
Representing edits as alignments
▪ So, when matching one word to another one, consider the last characters
of strings s and t.
▪ If we are lucky enough that they ALREADY match,
▪ then we can simply "cancel" and recursively find the edit distance between the two
strings left when we delete this last character from both strings.
▪ Otherwise, we MUST make one of three changes:
1) delete the last character of string x (this character matches to a “blank” on y)
2) delete the last character of string y (this character matches to a “blank” on x)
3) change the last character of string s to the last character of string t. (this will
correspond to a mismatch)
▪ Edit distance between an empty string and another string is the length of
the second string times insertion/deletion cost.
Defining Sub-Problems