

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Edit Distance
incomplete
2: Slow Edit Distance
incomplete
3: Edit Distance
incomplete
4: Dynamic Programming Edit Distance
incomplete
5: Fast Edit Distance – Review
incomplete
6: Memoization vs. Tabulation – Review
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
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!
Complete the edit_distance formula using dynamic programming. It should be able to compute the distance between long words efficiently.
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 |