





















































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
Lecture notes on the edit distance algorithm and its application to spell checkers, as well as an introduction to the knapsack problem and its solution using dynamic programming. The edit distance algorithm calculates the minimum number of edits (insertions, deletions, and substitutions) required to transform one string into another. The knapsack problem involves selecting items with given weights and values to maximize the total value within a given capacity.
Typology: Study notes
1 / 61
This page cannot be seen from the preview
Don't miss anything!






















































Edyta Szyma ´nska [email protected]
Application: Spell Checkers
Application: Spell Checkers ocurrance^? “Perhaps you mean
occurrence^ ?”
Application: Spell Checkers ocurrance^? “Perhaps you mean
occurrence^ ?” ocurrance^ and occurrence^ are^
close by
Application: Spell Checkers ocurrance^? “Perhaps you mean
occurrence^ ?” ocurrance^ and occurrence^ are^
close by How to define “closeness”? minimum number of “edits”-insertions, deletions and substitutions ofcharacters needed to transform string
x^ into string^ y. Example 1:^ d(to, fro
)= 2, to→^ fo (substitution)
→^ fro (insertion)
Solution? - dynamic programming?
Solution? - dynamic programming ?What are the subproblems? Example 2:^ d(exponential, polynomial
) =?^ CS3510 A, Fall 2005 – p. 3/
Solution? - dynamic programming ?What are the subproblems? Example 2:^ d(exponential, polynomial
possible subproblem: the smallest number of edits neededto transform some prefix of
x,^ say^ expo^ into some prefix of y,^ say^ pol.
Solution? - dynamic programming ?What are the subproblems? Example 2:^ d(exponential, polynomial
possible subproblem: the smallest number of edits neededto transform some prefix of
x,^ say^ expo^ into some prefix of y,^ say^ pol. How to transform
expo^ to^ pol^? left to right right to left middle-out?
INPUT:^ two words
x^ :^ |x|^ =^ m^ and
y^ :^ |y|^ =^ n insert y[j], substitute x[i]^ →
y[j]
INPUT:^ two words
x^ :^ |x|^ =^ m^ and
y^ :^ |y|^ =^ n OUTPUT:^ E(m, n)
,^ where^ E(i, j)^ is the edit distance between prefixes^ x[1^... i
]^ and^ y[1^... j] To figure out^ E(
i, j)^ check^ x[i] =
y[j]. If^ x[i]^6 =^ y[j]^ then we have one of the following operations:^ delete x[i],^ insert y[j],^ substitute x
[i]^ →^ y[j]
INPUT:^ two words
x^ :^ |x|^ =^ m^ and
y^ :^ |y|^ =^ n OUTPUT:^ E(m, n)
,^ where^ E(i, j)^ is the edit distance between prefixes^ x[1^... i
]^ and^ y[1^... j] To figure out^ E(
i, j)^ check^ x[i] =
y[j]. If^ x[i]^6 =^ y[j]^ then we have one of the following operations:^ delete x[i], E
(i, j) =^ E(i^ −^1 , j
insert y[j], E(i, j
) =^ E(i, j^ −^ 1) + 1 substitute x[i]^ →
y[j]^ E(i, j) =^ E
(i^ −^1 , j^ −^ 1) + 1^ CS3510 A, Fall 2005 – p. 4/
INPUT:^ two words
x^ :^ |x|^ =^ m^ and
y^ :^ |y|^ =^ n OUTPUT:^ E(m, n)
,^ where^ E(i, j)^ is the edit distance between prefixes^ x[1^... i
]^ and^ y[1^... j] To figure out^ E(
i, j)^ check^ x[i] =
y[j]. If^ x[i]^6 =^ y[j]^ then we have one of the following operations:^ delete x[i], E
(i, j) =^ E(i^ −^1 , j
insert y[j], E(i, j
) =^ E(i, j^ −^ 1) + 1 substitute x[i]^ →
y[j]^ E(i, j) =^ E
(i^ −^1 , j^ −^ 1) + 1 Otherwise (x[i] =
y[j]) we have^ E
(i, j) :=^ E(i^ −^1 , j
Base case:^ E(
, j) =^ j^ and^ E(i,
CS3510 A, Fall 2005 – p. 4/
INPUT:^ two words
x^ :^ |x|^ =^ m^ and
y^ :^ |y|^ =^ n OUTPUT:^ E(m, n)
,^ where^ E(i, j)^ is the edit distance between prefixes^ x[1^... i
]^ and^ y[1^... j] To figure out^ E(
i, j)^ check^ x[i] =
y[j]. If^ x[i]^6 =^ y[j]^ then we have one of the following operations:^ delete x[i], E
(i, j) =^ E(i^ −^1 , j
insert y[j], E(i, j
) =^ E(i, j^ −^ 1) + 1 substitute x[i]^ →
y[j]^ E(i, j) =^ E
(i^ −^1 , j^ −^ 1) + 1 Otherwise (x[i] =
y[j]) we have^ E
(i, j) :=^ E(i^ −^1 , j
Base case:^ E(
, j) =^ j^ and^ E(i,
CS3510 A, Fall 2005 – p. 4/