Slide 5
Slide 5 text
First solution
● Lets just try and find the minimum change count between A and B
● We define best_cost(A,B) as the min change count between A and B
● Now there’s three recursive possibilities:
○ Same: best_cost(A,B) = best_cost(A[1..],A[1..]) if A[0] == B[0]
○ Insert: best_cost(A,B) = 1+best_cost(A,B[1..])
○ Delete: best_cost(A,B) = 1+best_cost(A[1..], B)
○ Base case: best_cost(“”,””) = 0
● Problem: this is exponential, but best_cost gets called with the same
parameters a lot!