We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Dynamic Programming Edit Distance

Edit distance can actually be computed very quickly. It doesn't need to be O(3^n). At Mappy, our users noticed that when they were typing in longer phrases as their destination, the app would completely freeze up. Let's fix that performance problem!

Assignment

Complete the edit_distance formula using dynamic programming. It should be able to compute the distance between long words efficiently.

  1. For example, cat and bat would result in:

    c a t
    0 0 0 0
    b 0 0 0 0
    a 0 0 0 0
    t 0 0 0 0

    Now you should have a table with all the edit distances for all the substrings:

    c a t
    0 1 2 3
    b 1 1 2 3
    a 2 2 1 2
    t 3 3 2 1