Professional Documents
Culture Documents
CS 473ug: Algorithms: Chandra Chekuri Chekuri@cs - Uiuc.edu 3228 Siebel Center
CS 473ug: Algorithms: Chandra Chekuri Chekuri@cs - Uiuc.edu 3228 Siebel Center
CS 473ug: Algorithms: Chandra Chekuri Chekuri@cs - Uiuc.edu 3228 Siebel Center
Chandra Chekuri
chekuri@cs.uiuc.edu
3228 Siebel Center
University of Illinois, Urbana-Champaign
Fall 2007
Chekuri
CS473ug
Part I
Longest Increasing Subsequence
Chekuri
CS473ug
Chekuri
CS473ug
Chekuri
CS473ug
Example
Chekuri
CS473ug
Chekuri
CS473ug
Chekuri
CS473ug
Chekuri
CS473ug
Chekuri
CS473ug
Chekuri
max
CS473ug
L(j)
max
CS473ug
L(j)
max
L(j)
CS473ug
A Correct Recursion
Chekuri
CS473ug
A Correct Recursion
max
Chekuri
CS473ug
L(j)
A Correct Recursion
max
Chekuri
CS473ug
L(j)
A Correct Recursion
max
Chekuri
CS473ug
L(j)
max
Iterative algorithm:
for i = 1 to n do
L[i] = 1
for j = 1 to i 1 do
if aj < ai and 1 + L[j] > L[i]
L[i] = 1 + L[j]
Output maxni=1 L[i]
Running Time:
Chekuri
CS473ug
L(j)
max
Iterative algorithm:
for i = 1 to n do
L[i] = 1
for j = 1 to i 1 do
if aj < ai and 1 + L[j] > L[i]
L[i] = 1 + L[j]
Output maxni=1 L[i]
Chekuri
CS473ug
L(j)
max
Iterative algorithm:
for i = 1 to n do
L[i] = 1
for j = 1 to i 1 do
if aj < ai and 1 + L[j] > L[i]
L[i] = 1 + L[j]
Output maxni=1 L[i]
Chekuri
CS473ug
L(j)
Chekuri
CS473ug
Chekuri
CS473ug
Chekuri
CS473ug
Dilworths Theorem
Given sequence a1 , a2 , . . . , an the longest increasing subsequence
can be of size 1.
Chekuri
CS473ug
Dilworths Theorem
Given sequence a1 , a2 , . . . , an the longest increasing subsequence
can be of size 1.
Example: a1 > a2 > a3 > . . . > an
Chekuri
CS473ug
Dilworths Theorem
Given sequence a1 , a2 , . . . , an the longest increasing subsequence
can be of size 1.
Example: a1 > a2 > a3 > . . . > an
In the above example the longest decreasing sequence is of size n.
Chekuri
CS473ug
Dilworths Theorem
Given sequence a1 , a2 , . . . , an the longest increasing subsequence
can be of size 1.
Example: a1 > a2 > a3 > . . . > an
In the above example the longest decreasing sequence is of size n.
Question: Given a sequence of length n, can the longest increasing
sequence and the longest decreasing sequence be both small?
Chekuri
CS473ug
Dilworths Theorem
Given sequence a1 , a2 , . . . , an the longest increasing subsequence
can be of size 1.
Example: a1 > a2 > a3 > . . . > an
In the above example the longest decreasing sequence is of size n.
Question: Given a sequence of length n, can the longest increasing
sequence and the longest decreasing sequence be both small?
sequence is of length b nc + 1.
Exercise: give a sequence of length n in which both the longest
increasing subsequence and longest decreasing susbequence are no
more than b nc + 1.
Chekuri
CS473ug
Edit Distance
Part II
Edit Distance
Chekuri
CS473ug
Edit Distance
Chekuri
CS473ug
Edit Distance
Chekuri
CS473ug
Edit Distance
Chekuri
CS473ug
Edit Distance
Edit Distance
Chekuri
CS473ug
Edit Distance
Edit Distance
Chekuri
CS473ug
Edit Distance
Example
Chekuri
CS473ug
Edit Distance
Chekuri
CS473ug
Edit Distance
Chekuri
CS473ug
Edit Distance
Chekuri
CS473ug
Edit Distance
Chekuri
CS473ug
Edit Distance
Chekuri
CS473ug
Edit Distance
Chekuri
CS473ug
Edit Distance
Chekuri
CS473ug
Edit Distance
Chekuri
CS473ug
Edit Distance
A Recursive Solution
E [i, j]: edit distance between x[1..i] and y [1..j]
Chekuri
CS473ug
Edit Distance
A Recursive Solution
E [i, j]: edit distance between x[1..i] and y [1..j]
Case 1 xi aligned with xj .
E [i, j] = diff (xi , yj ) + E [i 1, j 1]
where diff (xi , yj ) = 0 if xi = yj , otherwise diff (xi , xj ) = 1
Chekuri
CS473ug
Edit Distance
A Recursive Solution
E [i, j]: edit distance between x[1..i] and y [1..j]
Case 1 xi aligned with xj .
E [i, j] = diff (xi , yj ) + E [i 1, j 1]
where diff (xi , yj ) = 0 if xi = yj , otherwise diff (xi , xj ) = 1
Case 2a xi is mapped to
and xi is to right of xj
E [i, j] = 1 + E [i 1, j]
Chekuri
CS473ug
Edit Distance
A Recursive Solution
E [i, j]: edit distance between x[1..i] and y [1..j]
Case 1 xi aligned with xj .
E [i, j] = diff (xi , yj ) + E [i 1, j 1]
where diff (xi , yj ) = 0 if xi = yj , otherwise diff (xi , xj ) = 1
Case 2a xi is mapped to
and xi is to right of xj
E [i, j] = 1 + E [i 1, j]
Case 2b yj is mapped to
and xi is to left of yj
E [i, j] = 1 + E [i, j 1]
Chekuri
CS473ug
Edit Distance
A Recursive Solution
Chekuri
CS473ug
Edit Distance
A Recursive Solution
Chekuri
CS473ug
Edit Distance
A Recursive Solution
Chekuri
CS473ug
Edit Distance
Iterative Solution
What is table?
Chekuri
CS473ug
Edit Distance
Iterative Solution
Chekuri
CS473ug
Edit Distance
Iterative Solution
Chekuri
CS473ug
Edit Distance
Iterative Solution
Chekuri
CS473ug
Edit Distance
Iterative Solution
for i = 0 to n
E [i, 0] = i
for j = 0 to m
E [0, j] = j
for i = 1 to n do
for j = 1 to m do
E [i, j] = min{diff (xi , yj ) + E [i, j], 1 + E [i 1, j], 1 + E [i, j 1]}
Running Time:
Chekuri
CS473ug
Edit Distance
Iterative Solution
for i = 0 to n
E [i, 0] = i
for j = 0 to m
E [0, j] = j
for i = 1 to n do
for j = 1 to m do
E [i, j] = min{diff (xi , yj ) + E [i, j], 1 + E [i 1, j], 1 + E [i, j 1]}
Chekuri
CS473ug
Edit Distance
Iterative Solution
for i = 0 to n
E [i, 0] = i
for j = 0 to m
E [0, j] = j
for i = 1 to n do
for j = 1 to m do
E [i, j] = min{diff (xi , yj ) + E [i, j], 1 + E [i 1, j], 1 + E [i, j 1]}
Chekuri
CS473ug
Edit Distance
Iterative Solution
for i = 0 to n
E [i, 0] = i
for j = 0 to m
E [0, j] = j
for i = 1 to n do
for j = 1 to m do
E [i, j] = min{diff (xi , yj ) + E [i, j], 1 + E [i 1, j], 1 + E [i, j 1]}
CS473ug
Edit Distance
Example
Chekuri
CS473ug
Edit Distance
Chekuri
CS473ug