0% found this document useful (0 votes)
2 views

Lecture 24

The document discusses the concept of edit distance, which measures the number of operations needed to transform one string into another through deletion, insertion, substitution, and matching. It explains the definitions of edit distance, optimal transcripts, and global string alignment, along with a recurrence relation for calculating edit distance. An example is provided to illustrate the computation of edit distance between two specific strings.

Uploaded by

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

Lecture 24

The document discusses the concept of edit distance, which measures the number of operations needed to transform one string into another through deletion, insertion, substitution, and matching. It explains the definitions of edit distance, optimal transcripts, and global string alignment, along with a recurrence relation for calculating edit distance. An example is provided to illustrate the computation of edit distance between two specific strings.

Uploaded by

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

Design and

Analysis of
Algorithm
Lecture 24: Dynamic Programming

Dr. Tauheed
Contents
Edit Distance

2
Edit Distance: Introduction
One measure of similarity between two strings is their edit distance.

This is a measure of the number of operations required to transform the first string into the other.

Single character operations:


• Deletion of a character in the first string
• Insertion of a character in the first string
• Substitution of a character into the first string
• Match a character in the first string with a character of the second.
Example Transform vintner to writers

vintner replace v with w  wintner


wintner insert r after w  wrintner
wrintner match i  wrintner
wrintner delete n  writner
writner match t  writner
writner delete n  writer
writer match e  writer
writer match r  writer
writer insert s  writers
Definitions
Let = {I, D, R, M} be the edit alphabet

An edit transcript of two strings is a string over describing a transformation of one


string into another.

The edit distance between two strings is defined as the minimum number of edit
operations needed to transform the first into the second. Matches are not included in
the count.
Definitions : Optimal Answers
Let = {I, D, R, M} be the edit alphabet

An optimal transcript is an edit transcript with the minimal number of edit operations
for transforming one string into another.

The edit distance problem entails computing the edit distance between two strings
along with an optimal transcript.
String Alignment
A global alignment of strings and is obtained by:
1. Inserting dashes/spaces into or at the ends of and .
2. Aligning the two strings s.t. each character/space in either string is opposite a
unique character/space in the other string.

Example 1: Example 2:
S1 = qacdbd S2 = qawxb S1 = vintner S2 = writers
qac-dbd v-intner-
qawx-b– wri-t-ers
Edit Distance
D(i,j), the edit distance of S1[1..i] and S2[1..j] is the minimum number of edit operations
needed to transform the first i characters of S1 into the first j characters of S2.

• Observation : There are many possible ways to transform one string into another.
Edit Distance: Approach
• The general recurrence is given by:

Here

• Basic argument: D(i,j) must be one of :


1. D(i - 1, j) + 1 for D(i,j) are:
2. D(i, j - 1) + 1 and

3. D(i - 1, j - 1) + t (i,j)

There are NO other ways of creating S2[1..j] from S1[1..i].


Example 1
Compute the edit distance from AECDB to ABCD
Fill in the base condition values.

A B C D
Use following recurrence to fill other values 0 1 2 3 4
A 1 0 1 2 3
D(i,j) = min[D(i - 1, j) + 1, D(i, j - 1) + 1, D(i - 1, j - 1) + t (i,j)]
E 2 1 1 2 3
where C 3 2 2 1 2
D 4 3 3 2 1
B 5 4 3 3 2

You might also like